服务器修改密钥登陆就登陆不上,securecrt用密钥安全登陆服务器

通过Linux服务器端生成密钥对来提供认证1,执行命令生成 生成公私钥ssh-keygen -t rsa -b 4096

确认生成文件的所在目录(默认为~/.ssh)及密码(可以为空,建议输入密码)

ssh-keygen参数解释:-t rsa 类型rsa/dsa        -b 4096 长度

2,将公钥改名并放入/root/.ssh/目录cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys  # 服务器端的公钥

如果想更改为其它名字的文件,则要修改文件/etc/ssh/sshd_config中的参数为你要的名字#AuthorizedKeysFile .ssh/authorized_keys

另外还需要开启密钥登陆选项,以及RSA算法进行安全验证选项,修改/etc/ssh/sshd_config参数为RSAAuthentication yes

PubkeyAuthentication yes

3,用下载软件,例如winscp flashfxp等将 id_rsa 和 id_rsa.pub 这两个文件下载到自己电脑里,保证这两个文件是在同一个目录里,

在 SecureCRT 里创建新的或者修改以前的链接,注意图里所示,Authentication 里只选“PublicKey”这一种方式:

915293bfbff74e3fb388245efed58a63.png

然后点击“Properties…”,出现如下所示窗口

49629879833eb0019d3a0e1c2574c6b2.png

建议先测试一下用密钥登陆是否成功,如果成功则进行下一步,不成功千万不要进行下一步,会导致你登陆不进服务器。

4,取消服务器端ssh默认支持Password认证,修改完成后服务器将不支持用密码登陆:#vi /etc/ssh/sshd_config

PasswordAuthentication no   #默认为yes

如果出先如下错误

Public-key authentication with the server for user root failed. Please verify username and public/private key pair.

如果是批量执行的话可以用shell脚本来修改服务器登陆为密钥登陆#开启密钥登陆

sed -i 's/#RSAAuthentication yes/RSAAuthentication yes/g' /etc/ssh/sshd_config

sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config

sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/g' /etc/ssh/sshd_config

#禁止密码登陆

sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值