How to Login via SSH Without Password in Linux
Introduction
To login via SSH without password we have to use ssh-keygen, ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.
Step 1: Create public and private keys using ssh-keygen
tom@tecdistro$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/tom/.ssh/id_rsa):[Press Enter] Created directory '/home/tom/.ssh'. Enter passphrase (empty for no passphrase):[Press Enter] Enter same passphrase again:[Press Enter] Your identification has been saved in /home/tom/.ssh/id_rsa. Your public key has been saved in /home/tom/.ssh/id_rsa.pub. The key fingerprint is: 54:63:39:4d:29:86:f9:12:93:f2:c0:05:9c:e6:43:83 tom@tecdistro The key's randomart image is: +--[ RSA 2048]----+ | +.+.+++.. | | E X *o=.o | | + =.= o | | o.o . | | .S. | | | | | | | | | +-----------------+
Step 2: Create .ssh directory to remote-machine
tom@tecdistro$ ssh beta@10.10.10.10 mkdir -p .ssh beta@testserver's password: [Enter Password Here]
Step 3: Copy the public key to remote-machine
Finally append a’s new public key to beta@10.10.10.10:.ssh/authorized_keys and enter beta@10.10.10.10 password one last time:
beta@testserver# cat .ssh/id_rsa.pub | ssh beta@10.10.10.10 'cat >> .ssh/authorized_keys' beta@testserver's password:
From now on you can log into remote-machine as beta user from tecdistro as a without password:
Step 4: Login to remote-machine without password
Now you can freely login to remote-machine without password to tecdistro server
# ssh beta@10.10.10.10
Step 5: Change the permissions
Change the permissions of .ssh to 700
# chmod 700 .ssh
Change the permissions of .ssh/authorized_keys2 to 640
# chmod 640 .ssh/authorized_keys
Leave a Reply
Want to join the discussion?Feel free to contribute!