远程登陆

安装 sshd

apt install openssh-server

ubuntu 允许使用 root 远程登陆

  1. 设置 root 密码
sudo passwd
  1. 修改配置文件/etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes
  1. 重启 sshd
service sshd restart

ssh 配置免密登录

sed -i 's/PubkeyAuthentication no/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/^#\s*\(AuthorizedKeysFile\s\+.*\)/\1/' /etc/ssh/sshd_config
systemctl restart sshd

生成密钥并同步至目标机器

ssh-keygen -t rsa
ssh-copy-id root@目标主机 IP

添加完节点信任关系之后,最好手动执行 ssh root@目标主机 IP 命令测试下是否可以无密码登录,防止因为 sshd 配置的原因,引起的无密码登录失败。