How to Secure Your EC2 Ubuntu Instance with a Password

Secure your EC2 Ubuntu instance with a strong password today. Follow these easy steps to set a password for the default user on your instance and protect your data.

Open a terminal or SSH client on your local machine.

1. Establish an SSH connection to your EC2 instance using the key pair associated with the instance. Replace your-instance-ip with the public IP address or DNS name of your EC2 instance, and your-key.pem with the path to your private key file:

 ssh -i your-key.pem ubuntu@your-instance-ip

2. Switch to root with:

 sudo su

3. Once connected to your EC2 instance, enter the following command to set the default password:

 passwd ubuntu

You will be prompted to enter a new UNIX password. Make sure to choose a strong and secure password.

After that, we will edit the configuration to modify the ssh login system for password. So, let’s open the configuration file with a nano editor. This will let us edit the default configuration.

 nano /etc/ssh/sshd_config

change PasswordAuthentication no to PasswordAuthentication yes

Next, we need to restart the sshd by running this command:

 service sshd restart

Now you can Run this command, and then give the password.

 ssh ubuntu@x.x.x.x