现在大多数商家在开通vps主机的时候都可以手动选择使用key密钥登入,后续只需要修改端口和关闭密码登录就可以了.
不过也有部分商家开通主机的时候不支援使用key登录的情况就需要开通主机后用密码登入设定密钥了。

你可以在本地使用puttygen.exe生成一个ppk文件,然后连线远程主机创建文件/root/.ssh/authorized_keys

# mkdir .ssh
# cd /root/.ssh/
# nano authorized_keys

然后复制puttygen.exe对话框生成的key 右键粘贴到远程主机即可。
接着进入nano /etc/ssh/sshd_config
修改端口
关闭密码登入

#PasswordAuthentication yes  更改为 PasswordAuthentication no 

对于 Ubuntu 22.04,请打开 (/etc/ssh/sshd_config.d/50-cloud-init.conf)并取消 PasswordAuthentication
重启ssh

# Ubuntu/Debian
sudo systemctl restart ssh
or
service sshd restart
# CentOS/Fedora
sudo service sshd restart

完成