In the Unix/Linux world, connecting to remote systems using SSH is common and performed frequently during the day. For some users or administrators, connecting to multiple systems is necessary either for administration, development or when running scripts that need to make a secure connection. To help automate logins for scripts or for frequent access, SSH can be easily setup to use private and public keys instead of passwords for SSH authentication.
To setup SSH for logging on without passwords, connect to your Computer (from where you will be making the SSH connection to a remote system). Next open a terminal window and from the prompt, generate your keys on the local computer by using the ssh-keygen program:
ssh-keygen -t rsa
and press enter.
When prompted for 'Enter file in which to save the key" press Enter to accept the default location.
When prompted to "Enter passphrase", press Enter twice for no passphrase.
When ssh-keygen has completed, you screen should look similar to the following:
Two new files have been created in the /home/wtn/.ssh directory which are your private key (id_rsa) and public key (id_rsa.pub):
Now that your keys have been created, copy the id_rsa.pub file to the remote computer and append its content to the ~/.ssh/authorized_keys file. Since SSH is running on the remote server, you can copy and append the file remotely from your computer using the following command:
ssh user@remotehost "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
Where:
user@remotehost is your user and hostname on the remote computer.
After you have successfully copy the file information to all your systems, you can now automate scripts and logon to SSH securely with needing to remember passwords!
Comments on How To Setup Secure Passwordless Authentication For SSH Connections On Linux Computers
you can also do:
ssh-copy-id -i user@server
Much easier 🙂