Add sudo user to Ubuntu and Add SSH Key login


Chris Brocklesby

Add sudo user to Ubuntu and any/or group also with SSH Key access, below are the commands and process.


ssh root@server_address

Add user

sudo adduser newuser

Then follow the instruction to finish the procedure

Adding user `newuser' ...
Adding new group `newuser' (1005) ...
Adding new user `newuser' (1004) with group `newuser' ...
Creating home directory `/home/newuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for newuser
Enter the new value, or press ENTER for the default
 Full Name []: Thuc Nguyen                
 Room Number []: 1234
 Work Phone []: 0123456789
 Home Phone []: 0987654321
 Other []: 
Is the information correct? [Y/n] Ysudo

Add user to sudo group

usermod -aG sudo newuser


su - newuser

Verify privileges by the sudo command

sudo ls -la /root

Add SSH Key

su - newuser

Create .ssh folder in home directory

mkdir ~/.ssh

Create authorized_keys file

nano ~/.ssh/authorized_keys

Verify SSH remote login

ssh newuser@server_address

... All done.

Chris BrocklesbyHead of Technology, Software Engineer, Technology lover and Family man based in Mapua, Tasman in New Zealand (Originally from Swansea UK).