Setup ssh login with pem file without password on ubuntu/linux server

Login to VPS with account user (not root)

mkdir pem
cd pem
ssh-keygen -b 2048 -f identity -t rsa -m PEM

Enter to leave passphare empty. It will gen 2 files in pem dir (identity and

Copy public key contents to authorized_keys

cat >> ~/.ssh/authorized_keys

Can check with

nano ~/.ssh/authorized_keys

Disable Password Authentication

sudo nano /etc/ssh/sshd_config

Update PasswordAuthentication from “yes” to “no” as below:

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

Restart SSH:

sudo service ssh restart

Download your private key to client side:

Copy the contents of the file private key file identity on vps to a key file identity.pem on your local system, just copy and paste the data into a new file.

cat ~/.ssh/pem/identity

The content look like this:


Set permission for pem on your local:

sudo chmod 600 identity.pem

Test login:

ssh -i identity.pem user@vps-ip


Hello there! 👋 I'm Vinh.