小言_互联网的博客

ssh使用秘钥登录

402人阅读  评论(0)

1. 先切换到要使用秘钥登录的用户

	su 用户名

2. 生成秘钥

[zj@linux ~]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zj/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):  #密码长度>4,可以留空
Enter same passphrase again: 
### 到这里就生成完了

 cd ~/.ssh/
 cat id_rsa.pub >> authorized_keys  
 chmod 600 authorized_keys
  chmod 700 ~/.ssh/

修改sshd_config

vim /etc/ssh/sshd_config
# 放开下面两个注释
RSAAuthentication yes
PubkeyAuthentication yes


#重启 SSH 服务
service sshd restart

3.客户端使用秘钥登录

下载前面生成的id_rsa文件,修改权限

chmod 600 id_rsa

使用秘钥连接

ssh  -p 端口号 用户名@ip  -i  id_rsa路径

如果前面设置了密码会提示输入密码

4.禁用密码登录

登录服务器后,修改sshd_config

vim /etc/ssh/sshd_config
#修改下面这条为no
PasswordAuthentication no

#重启 SSH 服务
service sshd restart

转载:https://blog.csdn.net/weixin_42255482/article/details/101624047
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场