VPS使用公钥登陆

351次阅读

 在客户端生成密钥

$ ssh-keygen -t rsa

# 把公钥拷贝至服务器

$ ssh-copy-id -i .ssh/id_rsa.pub server

# 也可以手动将.shh/id_rsa.pub拷贝至服务器用户目录的.ssh中,记得修改访问权限

# $ scp .shh/id_rsa.pub server:~/.ssh

# 在服务器中

$ cd ./.ssh/

$ mv id_rsa.pub authorized_keys

$ chmod 600 authorized_keys

$ vi /etc/ssh/sshd_config

RSAAuthentication yes #RSA认证

PubkeyAuthentication yes #开启公钥验证

AuthorizedKeysFile .ssh/authorized_keys #验证文件路径

PasswordAuthentication no #禁止密码认证

PermitEmptyPasswords no #禁止空密码

UsePAM no #禁用PAM

正文完