Passwordless SSH on Ubuntu Linux

Friday, May 15, 2020 By Ashish Doneriya

These steps are verified and tested several times and works flawlessly.

  1. Install openssh server
    sudo apt-get install openssh-server
  2. Remove previous .ssh directory (from home directory)
    rm -r ~/.ssh/
  3. Now Execute the below command. Leave all the field empty when asked.
    ssh-keygen -t rsa
  4. Execute the following commands after that
    cat ~/.ssh/ >> ~/.ssh/authorized_keys
    sudo chmod go-w ~/
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    exec ssh-agent bash

That’s it.

You can test on your machine.

ssh-copy-id localhost
ssh localhost

When you ssh localhost, it will not ask you password again.