Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how to create password less ssh between two AWS EC2 instances?

avatar

how to create password less ssh between 2 AWS EC2 instances.

1 ACCEPTED SOLUTION

avatar
Super Guru

@kishore sanchina

Subash is correct. It is not that different.

Pre-reqs:

1. access to your EC2 machine and using the pem key or credentials with root permissions.

2. already setup RSA keys on your 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. Check whether ssh-ing is permitted by the machine. It should. In /etc/ssh/sshd_config, 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> 

Try it and let me know.

View solution in original post

10 REPLIES 10

avatar
Super Collaborator

Hi @kishore sanchina

I assuming both are linux servers.

Please folllow the steps in mentioned url: http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/

avatar

Hi @subhash parise i know how to create password less ssh in linux. but i dont kown how to create password less ssh in ec2 instances.

avatar
Super Collaborator

Hi @kishore sanchina,

same mechanism will apply ec2 instances also 🙂

avatar
Super Guru

@kishore sanchina

Subash is correct. It is not that different.

Pre-reqs:

1. access to your EC2 machine and using the pem key or credentials with root permissions.

2. already setup RSA keys on your 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. Check whether ssh-ing is permitted by the machine. It should. In /etc/ssh/sshd_config, 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> 

Try it and let me know.

avatar
New Contributor

Kishore.. enable the below parameter under /etc/ssh/sshd_config

# To disable tunneled clear text passwords, change to no here!

PasswordAuthentication yes

and add the hostnames under /etc/hosts.. then follow the regular ssh procedure.

,

Hi Kishore,

to create password less ssh, first enable "authenticationpassword yes" option under /etc/ssh/sshd_config. add hostnames under /etc/hosts . then follow the regular ssh procedure. first check the ping is working from one instance to other or not?

avatar
Contributor

Hi how can i do the same with a local system running Windows?

avatar
Master Mentor

avatar
Contributor

Thanks @Jay SenSharma. I used this document but I can't achieve what I want to do : setup password-less SSH between my EC2 instances running RHEL7 from my local machine running Windows. I've open a new thread (here) to give more details.

avatar
Expert Contributor

This is probably the best link which I have found on how to setup the passwordless login using ssh-copy-id command on ec-2 instances.

https://superuser.com/questions/331167/why-cant-i-ssh-copy-id-to-an-ec2-instance

Probably, this might help.