Configuring New User on AWS EC2 with SSH (Ubuntu)
In this article, we will discuss how to configure a new user on an AWS EC2 instance running Ubuntu, and how to connect to the instance using SSH with the new user. We will cover key concepts such as creating a new user, creating a new key pair, and configuring SSH access for the new user.
Prerequisites
- An AWS account with access to EC2
- An existing EC2 instance running Ubuntu
- Internet connectivity
- The private key (.pem) file used to launch the EC2 instance
Step 1: Create a New User
The first step is to create a new user on the EC2 instance. To do this, connect to the instance using SSH with the default user (usually ubuntu), and use the useradd command to create a new user. For example, to create a new user called test-user, use the following command:
sudo useradd test-user
Step 2: Create a New Key Pair
Next, you will need to create a new key pair for the new user. This will allow the new user to connect to the EC2 instance using SSH. To create a new key pair, use the ssh-keygen command. For example, to create a new key pair called test-user, use the following command:
sudo su test-user
ssh-keygen -t rsa -b 4096 -C "[email protected]"
This will create a new private key file (test-user.pem) and a new public key file (test-user.pub). Make sure to keep the private key file secure, as it will be used to authenticate the new user when connecting to the EC2 instance using SSH.
Step 3: Configure SSH Access for the New User
The final step is to configure SSH access for the new user. To do this, you will need to copy the new user's public key to the authorized_keys file in the ~/.ssh directory. This will allow the new user to authenticate using their private key when connecting to the EC2 instance using SSH.
First, use the cd command to navigate to the ~/.ssh directory. Then, use the cat command to display the contents of the new user's public key file. Finally, use the > operator to append the public key to the authorized_keys file.
cd ~/.ssh
cat test-user.pub >> authorized_keys
Step 4: Connect to the EC2 Instance Using SSH
Now that you have created a new user and configured SSH access for them, you can connect to the EC2 instance using SSH with the new user. To do this, use the ssh command with the new user's username and the path to their private key file. For example:
ssh test-user@ec2-instance-ip-address -i path/to/test-user.pem
In this article, we have discussed how to configure a new user on an AWS EC2 instance running Ubuntu, and how to connect to the instance using SSH with the new user. We have covered key concepts such as creating a new user, creating a new key pair, and configuring SSH access for the new user. By following the steps outlined in this article, you should be able to create a new user and connect to your EC2 instance using SSH with the new user.