centos下配置ssh使用密钥

查询了网上的一些教程,然后根据自己的实际操作,记录自己实际配置ssh密钥的过程:

首先在centos终端切换到要链接的用户,比如用户ssh

使用该用户生成密钥:

ssh-keygen -t rsa

中间需要输入密钥的口令

默认会在/home/ssh/.ssh 下面生成id_rsa 和 id_rsa.pub 两个文件

将id_rsa.pub重名命为: authorized_keys

mv id_rsa.pub authorized_keys

然后将id_rsa文件剪切到需要使用putty登陆的机器上

配置sshd的配置文件,开启密钥验证

gedit /etc/ssh/sshd_config

然后去掉如下三行代码前的注释:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile    .ssh/authorized_keys
UsePAM no

然后去掉密码验证

#PermitEmptyPasswords no
PasswordAuthentication no

保存重启sshd服务

service sshd restart

然后使用puttygen.exe将id_rsa转化为ppk文件

然后使用putty链接即可

我第一次链接也是遇到了错误,按照网上说的更改现需要密码验证,然后关闭,没有生效

最后重新使用puttygen.exe重新转化ppk文件,然后就可以了!

原文地址:https://www.cnblogs.com/waitfate/p/4292806.html