Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup passwordless ssh on AWS

Tags:

ssh

amazon-ec2

How do I setup passwordless ssh between nodes on AWS cluster

like image 895
alex Avatar asked Jan 04 '11 13:01

alex


2 Answers

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> 
    
like image 126
Mayank Jaiswal Avatar answered Oct 06 '22 18:10

Mayank Jaiswal


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

like image 44
Vikas Hardia Avatar answered Oct 06 '22 17:10

Vikas Hardia