Add and Log In to an AWS EC2 Instance with a sudo User

Sam Julien
InstructorSam Julien
Share this video with your friends

Social Share Links

Send Tweet

Now that we are SSH'ed into our EC2 instance we can start modifying the server to actually run the application that we want to to run. Before we do that we want to switch users because you initially SSH you are the root user.

We will start by adding a ghost-admin user that we will give sudo permissions to. Once we are logged into that user we will update the server to ensure we are on the latest and greatest versions before installing additional software.

Instructor: [0:00] We're logged into our EC2 server. We need to make some updates. Before we do that, we need to create a new user for Ghost. It's a best practice to not do things as the root account if you can help it.

[0:16] You want to create, even if it's just a superuser admin account like we're about to make, but it's different than the root account. Let's go ahead and do that.

[0:24] First, let's clear this out. I am going to write clear, clear this out. I'm going to type, pseudo add user. I am going to call this user, ghost-admin. Give it a password that you can remember. I am going to make this super easy to remember for me. You can always change it later.

[0:42] You can skip all of these. This is a boon to asking you for information about this person, which is not actually a person. I am going to type, yes. Now we have our user.

[0:53] We need to add our user to the sudo superuser group, and we can do this with something called usermod. I'm going to say, sudo usermod, and we're going to give it two flags. We're going to say, -a, which means append, and capital G, which means groups, so add this to the following group.

[1:16] We're going to say sudo, or sudo, depending on how you want to say it. We're going to add this user to the group and then we specify the user, which is, Ghost-Admin. Modify the user, add Ghost-Admin to the sudo group, and hit enter. Great, so now that's done.

[1:33] Now, we're going to go ahead and log in as our Ghost-Admin user. We can use the su, or switch user command, and then a hyphen, and then Ghost-Admin. That's going to let us switch over.

[1:48] We need to enter that password that we created. I'm going to type that in quick, and now we're logged in. If I clear this out, you can see the Ghost-Admin there at the front of the prompt.

[1:59] Now, we're ready to do our updates to our server to make sure we're on the latest and greatest versions of everything. We need to do two commands for that, but we can put them in one line.

[2:09] We're going to say, sudo apt-get update. This is going to update the package lists for packages that need upgrading as well as new packages that have come to the repositories.

[2:21] Then we're going to do our &&, and we're going to say, sudo apt-get upgrade which is going to fetch the new versions of the packages and do those updates. We need to enter our password in for the Ghost-Admin account, and it's going to go grab those updates.

[2:38] Once the updates have been grabbed, it's going to ask me if I want to continue. You'll see it uses a whopping 929 kilobytes of space. Go ahead and hit yes. It will start to install all of those updates.

[2:50] This might take a few minutes. I'm going to go ahead and fast-forward this so you don't have to sit here and watch it. Now, all of our updates are installed and we're ready to go.