Linux VPS ยท Beginner Reference
Permissions & Users
Everything you need to understand Linux users, directories & permissions
01 ยท Prompt
Reading the Shell Prompt
root
@
srv1628184
:
~
#
- root Current logged-in username โ the superuser/administrator
- @ Separator meaning “at”
- srv1628184 Hostname of your server
- ~ Current directory โ tilde = home folder (
/rootfor root user) - # You are root. Regular users see
$instead
02 ยท Directories
Key Directory Structure
/ โ root of the entire filesystem
โโโ root/ โ root user’s home folder
โโโ home/ โ regular users live here
โ โโโ john/ โ john’s private folder
โ โโโ mary/ โ mary’s private folder
โโโ etc/ โ system config files
โโโ var/ โ logs, web files, etc.
- /root Root’s private home โ nobody else can enter
- /home/user Each user owns their own folder only
- ~ Shortcut for your own home โ changes per user
03 ยท Permission String
How to Read Permissions
–
r
w
x
|
r
–
x
|
r
–
–
type
r
w
x
r
–
x
r
–
–
| Who | Permissions | Meaning |
|---|---|---|
| Owner | r w x | Read, Write & Execute |
| Group | r – x | Read & Execute only |
| Others | r – – | Read only |
04 ยท Access Types
What r ยท w ยท x Mean
| Symbol | Name | On a File | On a Folder |
|---|---|---|---|
| r | Read | Open & view it | List files inside |
| w | Write | Edit or delete | Create/delete files inside |
| x | Execute | Run as a program | Enter with cd |
| – | Denied | Permission not granted | |
๐ก A folder needs
x to enter it with cd. Without it you get Permission denied even if you can see the folder.
05 ยท Access Matrix
Who Can Access What
| Directory | root | owner | other user |
|---|---|---|---|
| / | โ | read only | read only |
| /root | โ | โ | โ |
| /home/john | โ | โ | โ |
| /home/mary | โ | โ | โ |
| /etc | โ | read only | read only |
โ ๏ธ root overrides everything. Root can read, write and execute any file on the system regardless of what permissions are set.
06 ยท Commands
Essential Commands
$
ls -la
list files with permissions
$
pwd
show current directory path
$
whoami
show current username
#
adduser john
create a new user
#
usermod -aG sudo john
give sudo privileges
#
chmod 755 folder/
set folder permissions
#
chown john file.txt
change file owner
โ
# prompt = root ยท $ prompt = regular user.
Use
Use
sudo command as a regular user to run something as root.