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 identity.pub)

Copy public key contents to authorized_keys

cat identity.pub >> ~/.ssh/authorized_keysCode language: JavaScript (javascript)

Can check with

nano ~/.ssh/authorized_keysCode language: JavaScript (javascript)

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 noCode language: PHP (php)

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/identityCode language: JavaScript (javascript)

The content look like this:

— — -BEGIN RSA PRIVATE KEY — — -
……
— — -END RSA PRIVATE KEY — — -Code language: PHP (php)

Set permission for pem on your local:

sudo chmod 600 identity.pemCode language: CSS (css)

Test login:

ssh -i identity.pem user@vps-ipCode language: CSS (css)

vinhvd

Hello there! 👋 I'm Vinh.