Login to server using SSH key, without password

When login into server using SSH,  it’s more safe and easier using SSH key rather than password.

Before start, check my username on the computer
And use this username for easier setup

1. On remote server, switch to sudor

sudo su

2. Adding user and put password

adduser {user}

3. Switch to the created user

su {user}
cd ~/.ssh

4. Create key


5. Open ~/.ssh/id_rsa.pub from local computer and copy public key

ssh-rsa {some keys goes here}

6. Create authorized_keys file on remote server and paste public key

vi authorized_keys

7. Change Authorized key permission, make sure it has 600 permission

chmod 600 authorized_keys

8. Optionally, delete id_rsa, id_rsa.pub on remove server, it’s not used and not necessary to keep.

9. make login without password

sudo vi /etc/ssh/sshd_config

make sure PermitRootLogin line has like this:

PermitRootLogin without-password

10. Reload ssh

sudo service ssh restart

11. Try to login to remote server without password:

ssh {user}@{remove-server-ip}

12. Optionally, you can login without user name, just use ip address:
sudo su

vi /etc/sudoers.d/admin

Add like this


After change, give admin file permission to 400.

chmod 400 admin

13. If you want to allow login with password SSH or SFTP, change below.

sudo vi /etc/ssh/sshd_config

Then uncomment below

PasswordAuthentication yes