Password-Based Authentication For Linux Servers
EC2 instances(Linux servers) don’t have password-based authentication by default. You have to use the SSH key to connect your Linux instances. But in some cases, you want to use password-based authentication for your ec2 instances. Or you want your users to access the server using password-based authentication.
In this blog, we will learn how to set password-based authentication in your Linux EC2 instances.
Step 1: SSH your instance via private key.
I assuming you have a EC2 (Linux) instance and it is in up and running state.
From an SSH client, log in to your EC2 instance via your private key.
Use one of the following user names:
Linux Flavors | User Name |
---|---|
Centos | centos |
Ubuntu | Ubuntu |
Amazon Linux | ec2-user |
RHEL | root or ec2-user |
Suse | root or ec2-user |
Note: If ec2-user or root doesn't work, check with your AMI provider.
Step 2: Open SSH configuration file "sshd_config" file.
1> sudo vi /etc/ssh/sshd_config
Step 3: Find “PasswordAuthentication” parameter and update its value from “no” to “yes“.
1PasswordAuthentication yes
After the changes, save the file and exit.
Step 4: Restart the “sshd” service:
1> sudo service sshd restart
Step 5: Create SSH user.
1> adduser <USER-NAME>
Step 6: Set password for this user.
1> passwd <USER-NAME>
Step 7: Provide ROOT permission to this user.
1> usermod -aG sudo <USER-NAME>
By default, on CentOS/RHEL, members of the wheel group have sudo privileges. So, Run below command:
1usermod -aG wheel <USER-NAME>
Step 8: Now, test the configuration. SSH the server using password authentication.