How to enable root access using password in Amazon AWS EC2 instances

By default, password ssh access is disabled, and also root ssh access is disabled. Initially we can only login into an AWS EC2 instance using a pam key. In this article we will see what we need to do to make possible ssh login for a normal user and for the root user in a AWS EC2 instance. After you have created your instance and managed to login using the pam key follow the steps bellow to enable password ssh for root and other users. For this we need to edit the /etc/sshd/ssh_config file For root login enabling

  • you will need to uncomment the PermitRootLogin yes line.
  • comment the line PermitRootLogin forced-commands-only.
For password login
  • uncomment line PasswordAuthentication yes.
  • comment line PasswordAuthentication no.
vim /etc/sshd/ssh_config
# Authentication:


#LoginGraceTime 2m

PermitRootLogin yes  -- Uncomment
# Only allow root to run commands over ssh, no shell

#PermitRootLogin forced-commands-only  --comment

#StrictModes yes

#MaxAuthTries 6

#MaxSessions 10

.....
.....

PasswordAuthentication yes
#PermitEmptyPasswords no

# EC2 uses keys for remote access

#PasswordAuthentication no
 Next we need to restart the sshd service so the new configuration will get used.
[root@aodba]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
Now your AWS EC2 instance will be accessible by user/password. Note: 
  • i dont recommend login in using the root user, this can be dangerous and does not follow the best practices.
  • also user access using password is a quite risky.