linux ssh key 免密码登陆

来源:互联网 发布:海康网络球机安装教程 编辑:程序博客网 时间:2024/05/16 11:47

在登陆连接linux时,我们经常不想让连接进来的客户端知道服务器的登陆密码,此时我们就需要用到生成的密钥进行登陆。
生成密钥的流程如下:
1.生成公钥和密钥

ssh-keygen -t rsa

接下来直接点击回车就好了,它会在/root/.ssh目录或者/home/用户名/.ssh下生成id_rsa密钥、id_rsa.pub公钥

2.将公钥内容导入本机认证机构,并更改权限

 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys chmod 600 /root/.ssh/authorized_keys                  #更改认证文件的权限成600,这一步非常重要 chmod 700 /root/.ssh/                                 #更改/root/.ssh 目录的权限成700

3.管理员权限修改sshd_config文件,并重启sshd服务
修改sshd_config文件

RSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile      .ssh/authorized_keys
重启服务
service sshd restart

4.然后就可以将生成的密钥id_rsa拷贝到其他的机器上面进行测试登陆了

0 0