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)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024