Linux

Create a New User in Ubuntu with Home Directory and SSH Key Access

The Ubuntu VPS you spun up in AWS Lightsail comes with a default username as ubuntu. With that account, you can perform all the admin tasks on that server. But sometimes, you need to assign another user with or without admin privileges for other tasks.

And here is how to create a new user in Ubuntu with a home directory and SSH access with the private key.

First off, create the account.

sudo useradd -s /bin/bash -d /home/username -m -G sudo username

And that creates a new user with bash as the default login shell, a home directory, and sudo rights. Remove -G sudo if you don’t want the user to have the sudo rights.

Then reset the password for the user.

sudo passwd username

You can set up any password and you don’t have to remember it because you are going to use the SSH key to log in.

Now let’s generate a pair of SSH keys.

ssh-keygen

When prompted for the path and filename, type it in. By default, it will be saved in ./.ssh/id_rsa.

Once you have the key, copy the public key to the new user’s authorized_keys file.

First, use the following to view the public key.

cat ./.ssh/id_rsa.pub

And copy the key that displays on the screen and then run the following command to add it to the new user’s authorized_keys file.

sudo mkdir /home/username/.ssh
sudo chmod 0700 /home/username/.ssh
sudo -- sh -c "echo 'the_copied_public_key' > /home/username/.ssh/authorized_keys"
sudo chown -R username:username /home/username/.ssh/

The last step is to send off the private key to the new user and ask them to try.

edge

Share
Published by
edge

Recent Posts

Disable Copilot on Windows 11 via Group Policy GPO

If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…

9 months ago

Setting Default Fonts in Word, Excel, Outlook, and PowerPoint via Group Policy

In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…

9 months ago

Wake-On-LAN (WOL) with Windows and PowerShell

Wake-On-LAN is a networking standard that lets you wake up a computer from either a…

9 months ago

How To Remove Restrictions Set in A Password-Protected PDF File

First of all, this is not to bypass a PDF file that requires a password…

10 months ago

How To Move My Outlook Navigation Bar Back From Left Back To the Bottom

Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…

2 years ago

Headset with Microphone Echoing My Own Voice on Windows, What To Do?

One colleague came up to me the other day asking me to take look at…

2 years ago