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
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals