如何在 AWS 上设置无密码 ssh

发布于 2024-10-10 17:45:45 字数 32 浏览 3 评论 0原文

如何在 AWS 集群上的节点之间设置无密码 ssh

How do I setup passwordless ssh between nodes on AWS cluster

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

べ繥欢鉨o。 2024-10-17 17:45:45

以下设置无密码身份验证的步骤已针对 Centos 和 Ubuntu 进行了彻底测试。

假设:

  1. 您已经有权访问您的 EC2 计算机。可能正在使用 pem 密钥,或者您拥有具有 root 权限的 unix 用户的凭据。
  2. 您已经在本地计算机上设置了 RSA 密钥。私钥和公钥分别位于“~/.ssh/id_rsa”和“~/.ssh/id_rsa.pub”。

步骤

  1. 以 root 用户身份登录您的 EC2 计算机。
  2. 创建新用户

    useradd -m <你的名字>; 
    sudo su <你的名字>
    光盘 
    mkdir -p ~/.ssh
    触摸〜/.ssh/authorized_keys
    

    将本地计算机上的 ~/.ssh/id_rsa.pub 文件的内容附加到 EC2 计算机上的 ~/.ssh/authorized_keys。

    <前><代码>chmod -R 700 ~/.ssh
    chmod 600 ~/.ssh/*

  3. 确保机器允许 sshing。在文件 /etc/ssh/sshd_config 中,确保取消注释包含“PasswordAuthentication yes”的行。如果您对此文件进行任何更改,请重新启动 sshd 服务:

    service sshd restart # 在 Centos 上
    服务 ssh restart # 在 Ubuntu 上
    
  4. 您的无密码登录现在应该可以使用。在本地计算机上尝试以下操作:

    ssh -A <您的名字>@ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
    
  5. 让自己成为超级用户。打开/etc/sudoers。确保以下两行未注释:

    ## 允许群组wheel中的人运行所有命令
    %wheel 全部=(全部) 全部
    
    ## 没有密码也一样
    %wheel ALL=(全部) NOPASSWD: 全部
    

    将您自己添加到轮组。

    usermod -aGwheel<你的名字>; 
    

Following steps to setup password less authentication are tested thoroughly for Centos and Ubuntu.

Assumptions:

  1. You already have access to your EC2 machine. May be using the pem key or you have credentials for a unix user which has root permissions.
  2. You have already setup RSA keys on you local machine. Private key and public key are available at "~/.ssh/id_rsa" and "~/.ssh/id_rsa.pub" respectively.

Steps:

  1. Login to you EC2 machine as a root user.
  2. Create a new user

    useradd -m <yourname> 
    sudo su <yourname>
    cd 
    mkdir -p ~/.ssh
    touch ~/.ssh/authorized_keys
    

    Append contents of file ~/.ssh/id_rsa.pub on you local machine to ~/.ssh/authorized_keys on EC2 machine.

    chmod -R 700 ~/.ssh
    chmod 600 ~/.ssh/*
    
  3. Make sure sshing is permitted by the machine. In file /etc/ssh/sshd_config, make sure that line containing "PasswordAuthentication yes" is uncommented. Restart sshd service if you make any change in this file:

    service sshd restart # On Centos
    service ssh restart # On Ubuntu
    
  4. Your passwordless login should work now. Try following on your local machine:

    ssh -A <yourname>@ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
    
  5. Making yourself a super user. Open /etc/sudoers. Make sure following two lines are uncommented:

    ## Allows people in group wheel to run all commands
    %wheel ALL=(ALL)       ALL
    
    ## Same thing without a password
    %wheel ALL=(ALL)       NOPASSWD: ALL
    

    Add yourself to wheel group.

    usermod -aG wheel <yourname> 
    
心如狂蝶 2024-10-17 17:45:45

这可能会帮助某人

复制机器上的 pem 文件,然后将 pem 文件的内容复制到 .ssh/id_rsa 文件,您可以使用下面的命令或您自己的

cat my.pem > ~/.ssh/id_rsa

尝试 ssh localhost 它应该可以工作,并且与集群中的其他机器相同

This may help someone

Copy the pem file on the machine then copy the content of pem file to the .ssh/id_rsa file you can use bellow command or your own

cat my.pem > ~/.ssh/id_rsa

try ssh localhost it should work and same with the other machines in the cluster

罪歌 2024-10-17 17:45:45

我如何使 Passwordless shh 在两个实例之间工作如下:

  • 创建 ec2 实例 - 它们应该位于同一子网中并具有相同的安全组

  • 在它们之间打开端口 – 确保实例可以相互通信。使用默认安全组,该安全组具有与此案例相关的一条规则:

    • 类型:所有流量
    • 来源:自定义 - 安全组 ID
  • 登录到您想要连接到其他实例的实例

  • 运行:
    1 ssh-keygen -t rsa -N "" -f /home/ubuntu/.ssh/id_rsa
    生成新的 rsa 密钥。

  • 将您的 AWS 私有密钥复制为 ~/.ssh/my.key(或您想要使用的任何名称)

  • 确保将权限更改为 600
    1 chmod 600 .ssh/my.key

  • 将公钥复制到您想要无密码连接的实例
    1 只猫 ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/my.key [电子邮件受保护] "猫>>〜/.ssh/authorized_keys“

  • 如果您测试另一台机器的无密码 ssh,它应该可以工作。
    1 ssh 10.0.0.X

how I made Paswordless shh work between two instances is the following:

  • create ec2 instances – they should be in the same subnet and have the same security group

  • Open ports between them – make sure instances can communicate to each other. Use the default security group which has one rule relevant for this case:

    • Type: All Traffic
    • Source: Custom – id of the security group
  • Log in to the instance you want to connect from to the other instance

  • Run:
    1 ssh-keygen -t rsa -N "" -f /home/ubuntu/.ssh/id_rsa
    to generate a new rsa key.

  • Copy your private AWS key as ~/.ssh/my.key (or whatever name you want to use)

  • Make sure you change the permission to 600
    1 chmod 600 .ssh/my.key

  • Copy the public key to the instance you wish to connect to passwordless
    1 cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/my.key [email protected] "cat >> ~/.ssh/authorized_keys"

  • If you test the passwordless ssh to the other machine, it should work.
    1 ssh 10.0.0.X

朮生 2024-10-17 17:45:45

我如何在两个实例之间设置无密码身份验证如下:

  1. 从AWS控制台启动两个EC2实例(还为每个实例创建新的访问密钥。假设实例为server_instance和目标实例)。
  2. 现在您的目标是设置无密码身份验证,这样您就可以从 server_instance 登录到 target_instance 而无需输入密码。
  3. 现在登录到server_instance(通过任何终端)。
  4. 现在转到位置 cd ~/.ssh 并创建一个文件 vim target_instance_key.pem 并粘贴 target_instance 访问密钥的内容(该密钥是在 AWS 中启动 target_instance 期间创建的) console)在 target_instance_key.pem 内并保存文件。
  5. 现在不要忘记更改 target_instance_key.pem 的权限,即 chmod 600 target_instance_key.pem
  6. 现在通过 ssh-keygen -t rsa 创建 rsa 密钥>
  7. 现在执行命令 ssh-copy-id -f "-o IdentityFile ~/.ssh/target_instance_key.pem" ubuntu@ ,指纹类型 yes 并输入。
  8. 这样,无密码身份验证就完成了。
  9. 执行命令 ssh ubuntu@,您已通过无密码身份验证从 server_instance 登录到 target_instance。

注意:
server_instance 可以是任何计算机(即 EC2 实例(或)您的本地计算机)。

How Did I Setup Password-Less Authentication between two Instances is the following:

  1. Launch two EC2 Instances from AWS Console(also create new access key for each instance. Assume instances as server_instance and target instance).
  2. Now your goal is to setup Password-Less Authentication so, you can Log in to target_instance from server_instance without entering the password.
  3. Now Log in to the server_instance(through any teminal).
  4. Now go to the location cd ~/.ssh and create a file vim target_instance_key.pem and paste the contents of target_instance access key (which is created during launch of target_instance in AWS console) inside target_instance_key.pem and save the file.
  5. Now don't forget to change the permission of target_instance_key.pem i.e chmod 600 target_instance_key.pem
  6. Now create rsa keys by ssh-keygen -t rsa
  7. Now execute the command ssh-copy-id -f "-o IdentityFile ~/.ssh/target_instance_key.pem" ubuntu@<TARGET_INSTANCE-PUBLIC-IP> and for fingerprint type yes and enter.
  8. So Password-Less Authentication is done.
  9. Execute the command ssh ubuntu@<TARGET_INSTANCE_PUBLIC-IP-ADDRESS> and you have Logged in to the target_instance from server_instance through Password-Less Authentication.

NOTE :
server_instance can be any machine(i.e, EC2 instance (or) your local machine).

梦过后 2024-10-17 17:45:45

您可以使用 ssh 密钥,如下所述:
http://pkeck.myweb.uga.edu/ssh/

you can use ssh keys like described here:
http://pkeck.myweb.uga.edu/ssh/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文