User
Table of contents
Users
- Logout as user:
ctrl d
- Change user:
su - username
- Change to root:
su - root
, orsudo -i
- Set password for root:
sudo passwd
- Add user:
adduser username
, system will ask to enter password,enter
x 2 for no password. - Get users and permission
usermod -aG sudo [user-name] users ls -al
User in file
Add user www-data
inside the nginx.config
file is the same as running chmod -R www-data
.
Password control
- Login as root
- Run
vim /etc/sudoers
orsudo visudo
- Add
[user-name] ALL=(ALL) NOPASSWD:ALL
to the last line ofsudoers
file
Change user-name
sudo usermod -l [new-Username] [old-Username]
Permission with chown
& chmod
chown -R user:www-data /var/www/
- chown: change Owner
- user: the user
- www-data: the group
- /var/www/: the directory you want the user have the permission
chmod -R 777 /var/www
- to give the user ALL for the directory of /var/www
- Example folders
chmod -R 750 /var/www/example.com
chmod -R 755 /var/www/example.com/wp-content
chmod -R 777 /var/www/html/wp-content/
Delete user
- To delete user
deluser username
List user
cut -d: -f1 /etc/passwd
less /etc/passwd
Linux User Permission logics
R - read - 4 bits, read it
W - write - 2 bits, write / modify it
X - execute - file 1 bit, execute it
u - the owner user
g - the owner group
o - others (neither u, nor g)
a - all users
Permission chart
Triplet for u (owner user): | rwx => 4 + 2 + 1 = 7 |
Triplet for g (owner group): | r-x => 4 + 0 + 1 = 5 |
Triplet for o (neither u, nor g): | r-x => 4 + 0 + 1 = 5 |
Example
-rwx r-x r-x (755) => - rwx r-x r-x => - (-
is file, d
is directory), rwx (owner user) = 7, r-x (group) = 5, r-x (other user) = 5
Change permission chmod
ls -l
# output to see permission
chmod +x [path-to/file1]
# all user gets `+x`
chmod u+x [path-to/file1]
# owner user gets `+x`
chmod g+x [path-to/file1]
# group gets `+x`
chmod o+x [path-to/file1]
# other gets `+x`