Adding a New User

It is not recommended only to have a root user on your server, thus we will set up a new user account.

The process is fairly straightforward:

adduser username

Provide a secure password, and your new user account is created.

We will want occasional higher privileges:

usermod -aG sudo username

And you are done! Read the Securing Your Instance guide for increased security.

SSH login with a new username

Next, we will allow the newly created. Go to the new User's folder and create .ssh folder and authorized_keys file, and change its file permissions:

cd /home/<username>
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
chown -R <username>:<username> .ssh

To authenticate the new user, you will need to copy the public key corresponding to the user:

echo "<PUBLIC_KEY_LINE" >> .ssh/authorized_keys

You can now login from your workstation:

ssh <username>@<server_ip>

Alternatively, you can copy the entire authorized_keys file from the root user:

cp /root/.ssh/authorized_keys /home/<username>/.ssh/

Make sure to give an ownership of .ssh folder to <username>:

chown -R <username>:<username> .ssh

Last updated