...
If you already have an SSH key, you can skip this step. You can just hit Enter for the key and both passphrases (less secure):
Code Block localhost:~$$> ssh-keygen -t rsa -b 2048 -f mykey.key Generating public/private rsa key pair. Enter file in which to save the key (/home/username/.ssh/id_rsa): .ssh/mykey Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/username/.ssh/mykey. Your public key has been saved in /home/username/.ssh/mykey.pub.
Copy the public key of your computer to the trusted keys of the target server:
Code Block language bash localhost:~$ ssh-copy-id -i .ssh/mykey user@remotehost user@remotehost's password: ••••••••
Now try logging into the machine, with
ssh 'user@remotehost'
to verify the keys we’ve added:Code Block localhost:~$ # Create the .ssh directory: localhost:~$ mkdir ~/.ssh localhost:~$ # Set the right permissions: localhost:~$ chmod 700 ~/.ssh localhost:~$ # Create the authorized_keys file: localhost:~$ touch ~/.ssh/authorized_keys localhost:~$ # Set the right permissions: localhost:~$ chmod 600 ~/.ssh/authorized_keys localhost:~$ # verifyVerify localhost:~$ ls ~/.ssh/authorized_keys
Finally check you can log in using your new key…
Code Block localhost:~$ ssh id@server user@remotehost:~$
You may also want to look into using
ssh-agent
if you want to try keeping your keys protected with a passphrase (more secure).
...