如何在AWS上设置无密码ssh

ale*_*lex 6 ssh amazon-ec2

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

May*_*wal 7

以下步骤设置密码,对Centos和Ubuntu进行彻底测试.

假设:

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

脚步:

  1. 以root用户身份登录EC2计算机.
  2. 创建一个新用户

    useradd -m <yourname> 
    sudo su <yourname>
    cd 
    mkdir -p ~/.ssh
    touch ~/.ssh/authorized_keys
    
    Run Code Online (Sandbox Code Playgroud)

    将本地机器上的文件〜/ .ssh/id_rsa.pub的内容追加到EC2机器上的〜/ .ssh/authorized_keys.

    chmod -R 700 ~/.ssh
    chmod 600 ~/.ssh/*
    
    Run Code Online (Sandbox Code Playgroud)
  3. 确保机器允许sshing.在文件/ etc/ssh/sshd_config中,确保取消注释包含"PasswordAuthentication yes"的行.如果您对此文件进行任何更改,请重新启动sshd服务:

    service sshd restart # On Centos
    service ssh restart # On Ubuntu
    
    Run Code Online (Sandbox Code Playgroud)
  4. 您的无密码登录现在可以正常工作.在本地计算机上尝试以下操作:

    ssh -A <yourname>@ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
    
    Run Code Online (Sandbox Code Playgroud)
  5. 让自己成为超级用户.打开/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
    
    Run Code Online (Sandbox Code Playgroud)

    添加到轮组.

    usermod -aG wheel <yourname> 
    
    Run Code Online (Sandbox Code Playgroud)