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_keys
Code language: JavaScript (javascript)
Can check with
nano ~/.ssh/authorized_keys
Code 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 no
Code 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/identity
Code 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.pem
Code language: CSS (css)
Test login:
ssh -i identity.pem user@vps-ip
Code language: CSS (css)