-
Notifications
You must be signed in to change notification settings - Fork 0
SSH NoPass Login
To set up a passwordless SSH login in Linux all you need to do is to generate a public authentication key and append it to the remote hosts ~/.ssh/authorized_keys file.
Before generating a new SSH key pair first check if you already have an SSH key on your client machine because you don't want to overwrite your existing keys.
Run the following ls command to see if existing SSH keys are present:
$ ls -al ~/.ssh/id_*.pub
If there are existing keys, you can either use those and skip the next step or backup up the old keys and generate a new one.
If you see No such file or directory or no matches found it means that you do not have an SSH key and you can proceed with the next step and generate a new one.
The following command will generate a new 4096 bits SSH key pair with your email address as a comment:
ssh-keygen -t [ALGO] -b [SIZE] -C "[COMMENT]"
$ ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
To be sure that the SSH keys are generated you can list your new private and public keys with:
$ ls ~/.ssh/id_*
Now that you have generated an SSH key pair, in order to be able to login to your server without a password you need to copy the public key to the server you want to manage.
The easiest way to copy your public key to your server is to use a command called ssh-copy-id. On your local machine terminal type:
$ ssh-copy-id remote_username@server_ip_address
If by some reason the ssh-copy-id utility is not available on your local computer you can use the following command to copy the public key:
cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"