Steps to Perform SSH Login Without Password Using ssh-keygen and ssh-copy-id
Step 1: Generate the keys
> ssh-keygen
or
> ssh-keygen -t rsa
Step 2: Copy the public key to remote machine
> ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
or
> ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname.example.com
Alternatively, you can paste in the keys using SSH:
cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 “mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys”
Step 3: Login to remote machine
> ssh remote-host
If you have loaded keys to the ssh-agent using the ssh-add, then ssh-copy-id will get the keys from the ssh-agent to copy to the remote-host. i.e, it copies the keys provided by ssh-add -L command to the remote-host, when you don’t pass option -i to the ssh-copy-id.
> ssh-add
> ssh-add /Users/rajesh.kumar/.ssh/id_rsa
Step 4: Optional Step Four—Disable the Password for Root Login
> sudo nano /etc/ssh/sshd_config
Put the changes into effect:
> reload ssh
Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key:
> PermitRootLogin without-password
More Articles
Latest posts by Rajesh Kumar (see all)
- Medical Laboratory equipment manufacturing company - December 20, 2024
- Discover the Heart of India with Mera Apna Bihar - December 20, 2024
- Experience the Pulse of Bangalore with Bangalore Orbit - December 20, 2024