Setup Linode - Part 2 Users

David Carr

2 min read - 27th Oct, 2019


 

You shoukd not use the ROOT user for normal usage, its too dangerous instead its recommended to setup user accounts, here I'll set up a user for usage going forward.

 

How To Add a User

 

If you are signed in as the root user, you can create a new user at any time by typing:

adduser dave

one step required is to create a user password, keep a note of this as it will be required when running certain commands. The other details are optional.

 

To delete a user:

deluser dave

By default, a new user is only in their own group, which is created at the time of account creation, and shares a name with the user. In order to add the user to a new group, we can use the usermod command:

usermod -aG sudo dave

The -aG option here tells usermod to add the user to the listed groups.

 

Setup user permissions

Change username with the name of the user, this gives ownership of the var/www directory and its children

sudo chown -R dave:dave /var/www

 

Login as user

To log in as user under SSH without a password. 

while still logged in as root switch to the new user account.

su dave

Create a new directory called .ssh and restrict its permissions with the following commands:

mkdir ~/.ssh
chmod 700 ~/.ssh

Now open a file in .ssh called authorized_keys with VIM

vi ~/.ssh/authorized_keys

Open a new terminal instance to view the public key on your machine:

cat ~/.ssh/id_rsa.pub

Copy the key then go back to your connected terminal.

paste the key and by pressing I to be in write mode then after pasting press esc and :wq to exit.

You will now be able to login to your server as the user.

Type exit to exit from the user back to root. 
Type exit again to disconnect from the server.

You can now ssh in as the user:

ssh dave@ip
0 comments
Add a comment

Copyright © 2024 DC Blog - All rights reserved.