Generate and log in SSH with an RSA public key

1. Generate the key.

ssh-keygen -t rsa -P 123456 -f host -C 'key'

-t: key Type {dsa | ecdsa | ed25519 | rsa | rsa1}
-P: Passpharse (empty for no passpharse)
-f: key Filename/hostname
-C: Comment

2. Add it to your server.

scp host.pub root@your_server_ip:/root/
cat /root/host.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

3. Edit sshd_config.
vim /etc/ssh/sshd_config

Edit these configs.

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

4. Try to ssh with pub key.

ssh -p ssh_port username@domain/ip -i your_private_certification_path

ssh via a proxy.
ssh -p port user@ip -o ProxyCommand='nc -x proxy %h %p' -i path

5. If it works, you can edit the

PasswordAuthentication yes

to

PasswordAuthentication no

in sshd_config which means your server can only be SSHed with a pub key.
***NOTE: DO NOT edit this unless you are sure that you can ssh with pub key.***