如何在 AWS 集群上的节点之间设置无密码 ssh
以下设置无密码身份验证的步骤已针对 Centos 和 Ubuntu 进行了彻底测试。
假设:
- 您已经可以访问您的 EC2 机器。可能正在使用 pem 密钥,或者您拥有具有 root 权限的 unix 用户的凭据。
- 您已经在本地计算机上设置了 RSA 密钥。私钥和公钥分别位于“~/.ssh/id_rsa”和“~/.ssh/id_rsa.pub”。
Steps:
- 以 root 用户身份登录您的 EC2 计算机。
-
创建一个新用户
useradd -m <yourname>
sudo su <yourname>
cd
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
将本地计算机上的 ~/.ssh/id_rsa.pub 文件的内容附加到 EC2 计算机上的 ~/.ssh/authorized_keys 中。
chmod -R 700 ~/.ssh
chmod 600 ~/.ssh/*
-
确保机器允许 sshing。在文件 /etc/ssh/sshd_config 中,确保取消注释包含“PasswordAuthentication yes”的行。如果对此文件进行任何更改,请重新启动 sshd 服务:
service sshd restart # On Centos
service ssh restart # On Ubuntu
-
您的无密码登录现在应该可以使用了。在本地计算机上尝试以下操作:
ssh -A <yourname>@ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
-
让自己成为超级用户。打开/etc/sudoers
。确保以下两行未注释:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
将您自己添加到轮组中。
usermod -aG wheel <yourname>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)