Unix Icon

SSH Auto Login: Log into your server automatically

If you’re constantly logging into your server via SSH, I hope you’re logging in with RSA keys and SSH aliases to save your hands from unnecessary keystrokes. Follow these steps to learn to have SSH auto login for you.

Watch the Video

Generate Server RSA Keys

1. Log into your server via SSH

:~ ssh user@domain.com

2. Create a new RSA key

:~ ssh-keygen -t rsa

Hit return twice unless you want to set a password on the key.

3. Go to your .ssh folder

:~ cd .ssh

4. Put the public key into your authorized_keys file

:~ cat id_rsa.pub >> authorized_keys

5. Set perms on authorized_keys

:~ chmod 600 authorized_keys

6. Remove the public key

:~ rm id_rsa.pub

7. Close your SSH connection and go back to your local computer

Download the Server Private Key

8. Go to your .ssh directory

:~ cd .ssh

9. Secure file transfer the private key to your .ssh folder

:~ scp user@domain.com:~/.ssh/id_rsa ./

10. Create a folder for the key – Note: named it something related to the domain

:~ mkdir folder_name

11. Move the private key into the folder

:~ mv id_rsa folder_name

Set up an SSH Alias in the Config file

12. Open up the SSH config in your favourite editor

:~ sudo pico config

13. Enter the following details:

Host alias_name
Hostname domain.com
User username
PreferredAuthentication publickey
IdentifyFile ~/.ssh/folder_name/id_rsa

14. Save and close the file

15. Connect to your server with your alias

:~ ssh alias_name

It should now log you in without any authentication.

Continue Reading