@Sean101
Creating SSH Key
If you use Windows and using PuTTY to login to your VPS via SSH, you can use the software PuTTY-Gen to generate SSH key, you can download it from here
View attachment puttygen.zip
Once your download is complete, choose the options as below and press
Generate.
While creating, you need to move the mouse over the blank area as below (under the loading bar)
Once created, you will see it is like this.
Now put the keyphrase for it by filling keypharse above.
Then click Save Private Key and store it in a safe place or on Dropbox and you can use later.
Public key is charaters which starts with
ssh-rsa....... This will need to copy to your server in ssh folder in next steps.
Adding public key into VPS
Code:
mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys
If ssh folder is created, just start from the command
chmod 0700 ~/.ssh
Then open the file authorized_keys in directory .ssh in the user's home directory and copy the entire character of the public key into this file.
Code:
nano ~/.ssh/authorized_keys
Copy public key and right click to paste into authorized_keys file, Ctrl + O to save and Ctrl+X to exit.
Note:
SSH Key will not work if you are enabling SELinux. Please disable SELinux by opening the file
/etc/selinux/config
Find
SELINUX = enforcing and replaced with
SELINUX = disabled
After that using reboot command to reboot your server
To check if SSH key is working or not, just create a new account and at SSH -> Auth, browse your public key file created before
Save this account for next logins
Now when you login to your VPS, it will prompt you the keyphrase and you need to type keyphases to login.
For example, you should see these
Code:
login as: root
Authenticating with public key "rsa-key-20160920"
Passphrase for key "rsa-key-20160920":
Last login: Mon Sep 19 23:34:26 2016 from YOUR_IP
Turn off password function
After the test, if you were able to log on to the server using SSH Key, you can disable the password with following ways
Code:
nano /etc/ssh/sshd_config
and change to
Code:
PasswordAuthentication no
UsePAM no
Hope it helps!