Setup Linode - Part 2 Users
- Part 1 LAMP
- Part 2 Users
- Part 3 Upgrade PHP to 7.3
- Part 4 Apache Enable Mod rewrite
- Part 5 Composer
- Part 6 Virtual Hosts
- Part 7 Let's Encrypt
- Part 8 MySQL
- Part 9 Remote MySQL over SSH
- Part 10 Laravel
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:
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:
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.
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
Open a new terminal instance to view the public key on your machine:
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: