ssh免密登录

来源:互联网 发布:信鸽软件 编辑:程序博客网 时间:2024/05/22 04:56

SSH免密登录

1.安装openssh

yum install openssh

2.生成公钥和私钥

ssh-keygen

等同于ssh-keygen -t rsa

运行上面的命令后,系统会出现一系列提示,可以一路回车。例如:

$ ssh-keygen

Generating public/private rsakey pair.

Enter file in whichto save thekey (/home/glowd/.ssh/id_rsa): Enter

特别说明:要不要对私钥设置口令(passphrase),如果担心私钥的安全,可以设置一个。没有特殊要求,直接回车,为空。

运行结束以后会在~/.ssh目录下生成两个文件:

id_rsa:私钥

id_rsa.pub:公钥

3.导入公钥到认证文件,更改权限

导入本机公钥

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

将本机公钥拷贝到远程服务器

ssh-copy-id -i ~/.ssh/id_rsa.pub 服务器ip

例如:ssh-copy-id -i ~/.ssh/id_rsa.pub 10.5.96.45(第一台)

ssh-copy-id -i ~/.ssh/id_rsa.pub 10.5.96.46(第二台)

提示:(yes or no) yes 回车

输入远程服务器密码

更改权限

chmod 755 ~

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys

集群间每台重复以上命令。

测试:ssh 10.5.96.45 直接登录

原创粉丝点击