centos7 实现root ssh免密登入

centos7 实现root ssh免密登入

效果:直接 ssh root@IP 即可远程登入另一台服务器

centos7 实现root ssh免密登入_第1张图片

 

开启步骤

1、执行命令

ssh-keygen -t rsa

    (执行时按回车即可)

  生成之后会在用户的根目录生成一个 “.ssh”的文件夹

  进入“.ssh”会生成以下几个文件

  authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥

  id_rsa : 生成的私钥文件

  id_rsa.pub : 生成的公钥文件

  know_hosts : 已知的主机公钥清单

    如果希望ssh公钥生效需满足至少下面两个条件(生成时默认):

      1) .ssh目录的权限必须是700

       2) .ssh/authorized_keys文件权限必须是600

 

2、执行命令(进入 ~/.ssh)

cd ~/.ssh
ssh-copy-id -i id_rsa.pub root@(需要连接的服务器IP)

执行效果如下

[root@localhost .ssh]# ssh-copy-id -i id_rsa.pub [email protected]

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password:  (输入需连接服务器的root密码)



Number of key(s) added: 1



Now try logging into the machine, with:   "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

centos7 实现root ssh免密登入_第2张图片

centos7 实现root ssh免密登入_第3张图片

你可能感兴趣的:(centos7 实现root ssh免密登入)