4

两台服务器实现免密登录 - 永恒&

 1 year ago
source link: https://www.cnblogs.com/Sun-yuan/p/17155366.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

两台服务器实现免密登录

可以用于配置多台(>2)服务器之间的免密登录

使用shell的远程操作命令ssh,通过ssh协议,连接192.168.100.148服务器,执行echo 1命令。

ssh 192.168.100.148 'echo 1'

输出如下:

[root@hadoop001 ~]# ssh 192.168.100.148 'echo 1'
[email protected]'s password: 
1

需要输入192.168.100.148的登录密码

现在实现免密登录

目标:231访问248不需要输入密码

1、231生成密钥对

# cd /root/.ssh (如果没有.ssh, 请在root目录下mkdir .ssh chmod 755 .ssh)
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (直接回车)
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: (直接回车)
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:06:96:6b:56:0c:33:a4:24:16:8c:06:35:9b:98:8b:e7 [email protected]
img

2、将生成的公钥id_rsa.pub复制到148机器上

ssh-copy-id -i root/.ssh/id_rsa.pub [email protected]

说明:将231上生成的公钥文件id_rsa.pub复制到148的/root/.ssh/authorized_keys里,ssh-copy-id -i表示追加写的方式添加到authorized_keys。可以实现多个机器访问148.

[root@hadoop001 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/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: 

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.
[root@hadoop001 .ssh]# ssh [email protected] 'echo 1'
1

不用输入密码,表示配置成功了。

  1. 多台服务器的免密登录

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK