DEV Community

Sh Raj
Sh Raj

Posted on

Changing the Default Password on an EC2 Ubuntu Instance

Changing the Default Password on an EC2 Ubuntu 14 Instance

Amazon EC2 (Elastic Compute Cloud) is a popular web service that provides resizable compute capacity in the cloud. It's often used for hosting applications, websites, and other workloads. When launching an EC2 instance with Ubuntu 14.04, the default user is typically ubuntu, and by default, this user doesn't have a password set. Instead, you access the instance using SSH key pairs. However, there might be situations where you need to set or change the password for the ubuntu user or other users. This guide will walk you through the process of setting and changing the password on an EC2 Ubuntu 14 instance.

Prerequisites

  • An AWS account.
  • An EC2 instance running Ubuntu 14.04.
  • SSH key pair associated with your EC2 instance.
  • SSH client (e.g., PuTTY for Windows or Terminal for macOS/Linux).

Step-by-Step Guide

Step 1: Access Your EC2 Instance

  1. Open your terminal or SSH client.

  2. Connect to your EC2 instance using SSH. Replace <your-key-pair>.pem with your actual key pair file and ec2-user@your-instance-public-dns with your instance's public DNS.

   ssh -i <your-key-pair>.pem ubuntu@your-instance-public-dns
Enter fullscreen mode Exit fullscreen mode

Example:

   ssh -i my-key-pair.pem ubuntu@ec2-203-0-113-25.compute-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Step 2: Set or Change the Password for the ubuntu User

Once you are logged in to your instance, you can set or change the password for the ubuntu user.

  1. Set the password using the passwd command.
   sudo passwd ubuntu
Enter fullscreen mode Exit fullscreen mode
  1. Enter a new password when prompted. You will need to confirm the password by typing it again.
   Enter new UNIX password:
   Retype new UNIX password:
   passwd: password updated successfully
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the Password Change

To ensure that the password change was successful, you can try switching to the ubuntu user and using the new password.

  1. Switch to the ubuntu user.
   su - ubuntu
Enter fullscreen mode Exit fullscreen mode
  1. Enter the new password when prompted.
   Password:
Enter fullscreen mode Exit fullscreen mode

If you are not prompted for the password or if you want to log in using the password, you may need to adjust the SSH settings to allow password authentication.

Step 4: Enable Password Authentication (Optional)

By default, EC2 instances use key pair authentication, and password authentication might be disabled. To enable password authentication:

  1. Edit the SSH configuration file.
   sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode
  1. Find the following lines and modify them as shown:
   PasswordAuthentication yes
   PermitRootLogin yes
Enter fullscreen mode Exit fullscreen mode
  1. Save the file and exit the editor (Ctrl+O, Enter, Ctrl+X in nano).

  2. Restart the SSH service to apply the changes.

   sudo service ssh restart
Enter fullscreen mode Exit fullscreen mode

Step 5: Test Password Authentication

  1. Open a new terminal or SSH client window.

  2. Connect to your EC2 instance using the ubuntu username and the new password.

   ssh ubuntu@your-instance-public-dns
Enter fullscreen mode Exit fullscreen mode

You should now be able to log in using the password you set.

Conclusion

Changing the default password on an EC2 Ubuntu 14 instance is straightforward. By following these steps, you can ensure that your instance is secure and that you have the necessary access methods in place. Always remember to revert the SSH settings to disable password authentication if it is no longer needed to maintain security best practices.

Top comments (0)