1ssh-keygen -t ed25519
Previously, i used to use rsa
as the type, but i have since moved on to ed25519
. Ed25519 is a newer public-key algorithm which is faster (and safer) than RSA. Ed25519 public-key is also more compact, containing only 68 characters as compared to RSA 3072 that has 544 characters. Ed25519 is supported by OpenSSH so you should be good in almost all cases.
Github recommends passing it your email with -C which is then uses as a label.
1cd ~/.ssh && ssh-keygen -t ed25519 -C "hello@example.com"
1scp id_ed25519.pub user@remoteserver:location
On linux you can do
1ssh-copy-id user@123.456.789.123
2
3# ssh-copy-id -i ~/.ssh/mykey -p 1234 user@host
The remote server doesn’t like the authorizated_keys
file having too many permissions. For better security, change the authorizated_keys
file to 600
and the ~/.ssh/
folder to 700
. The permissions on .ssh
can not be any higher than 755.
1chmod 600 ~/.ssh/authorized_keys
2chmod 700 ~/.ssh
You might even have to change permissions for the /home
directory
1chmod go-w ~/
The config file for the ssh daemon is at:
/etc/ssh/sshd_config
You can also use the find
command to find the file location:
1find / -name sshd_config
Make a copy of the config file if you are afraid of messing it up
1cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
1service sshd restart
If you don’t know what the service name for ssh is, you can list all of the services to find out:
1service --status-all
You can create an SSH config file at ~/.ssh/config
and save all your SSH connection settings there. You will then be able to run ssh FOO
and connect with all the settings defined for the host FOO.
1# My settings for connecting to FOO server
2Host foo
3 #HostName www.myfooserver.com
4 HostName 123.456.789.123
5 User USERNAME
6 Port 22
7 IdentityFile ~/.ssh/MY_SSH_KEY
ssh-agent
and load your keysSee if ssh-agent is running:
1ps -e | grep [s]sh-agent
Run ssh-agent:
1ssh-agent /bin/bash
OR
1ssh-agent bash
OR
1eval $(ssh-agent)
Load ssh key:
1ssh-add ~/.ssh/id_ed25519
List loaded ssh keys:
1ssh-add -l
Copy your key to your clipboard with (Linux only):
1cat ~/.ssh/id_ed25519.pub | pbcopy
Simple as that. Though troubleshooting might be needed.
authorized_keys
file, on remote server, in the ~/.ssh
folder. If it doesn’t exist, create one.sshd_config
-v
.