【运维】两台Linux服务器SSH连接
服务器A 192.168.0.100
服务器B 192.168.0.200
服务器A ----》 服务器B
方法一 通过账号密码连接
回车直接输入密码即可连接成功
ssh -l root 192.168.0.200
方法二 通过公钥私钥连接(免密)
服务器001
1.查看是否已经生成公钥
ls -l ~/.ssh/id_rsa.pub
2. 如果没有公钥则执行 生成公钥。 -N代表不设置密码。
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
3. 查看公钥内容并复制 例如公钥内容为:AAABBBCCC
cat ~/.ssh/id_rsa.pub
服务器002
4. 配置公钥
输入 echo "你的公钥内容(把001的公钥粘贴到这里)" >> ~/.ssh/authorized_keys
例如
echo "AABBCC" >> ~/.ssh/authorized_keys
增加权限
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
5. 直连服务器002
ssh -l root 192.168.0.200
方法三
1. 连接服务器002
ssh -l root 192.168.1.200
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ED25519 key fingerprint is SHA256:ADFSDFSDFSDFSDF.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes
输入yes
Warning: Permanently added '192.168.1.100' (ED25519) to the list of known hosts.
2. 生成公钥
ssh-keygen -t ed25519
3. 查看公钥并复制 公钥内容: AAABBBCCC
cat /root/.ssh/id_ed25519.pub
服务器002
4. 配置公钥
输入 echo "你的公钥内容(把001的公钥粘贴到这里)" >> ~/.ssh/authorized_keys
例如
echo "AABBCC" >> ~/.ssh/authorized_keys
增加权限
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
5. 直连服务器002
ssh -l root 192.168.0.200
1527

被折叠的 条评论
为什么被折叠?



