Linux File Permissions - AidanP017/Aidan-SYS-255 GitHub Wiki
Overview
In this assignment, we secured /accounting and /management directories on our DHCP01 virtual machines in order to broaden our understanding of Linux users, groups, and file permissions.
How to Add a New User and Set its Password in DHCP01
To add a new user in DHCP01, take the following steps:
- If you do not have elevated privileges, type sudo -i and enter your password.
- Enter the command useradd "name for new user".
- Enter the command passwd "name of new user" and set a password for the user.
- Enter the command ls /home to verify that the new users have been added.
How to Add a New Group in DHCP01
To add a new group in DHCP01, take the following steps:
- Enter the command groupadd "name for new group".
Following, to add a user to the group, take the following steps:
- Enter the command usermod -aG "name of new group" "name of user".
How to Change the File and Directory Permissions for a User on DHCP01
To change the file and directory permissions for a user on DHCP01, take the following steps:
- Make sure you are logged in as a root user.
- Enter the chmod command.
-
- Following chmod, specify the type of read, write, and execute permissions that you wish to enable and disable for the user. Once you have done so, enter the file or directory that you wish for these permissions to apply to.
The types of rwx permissions vary and can be inputted as any of the following:
-
r --> Read the file's contents.
-
w --> Write or modify the file's contents.
-
x --> Execute the file.
-
rw- --> Can read, write, and modify a file.
-
r-x --> Can read and execute a file.
-
r-- --> Can only read a file.
-
+ --> Adds permissions for a file.
-
- --> Removes permissions for a file.
-
= --> Sets permissions to the specified values.
For the full command, you will enter something along the lines of this:
- chmod o+r "file"
- chmod o-wx "file"
- chmod o+rwx "file"
Important Commands
- su - "user" --- Allows you to become a user without having to log out.
- pwd --- Prints the path of the current working directory.
- echo --- Repeats what you typed following the word "echo". ** echo "..." > "file" --- Redirects the echo output and turns it into a file.
- chgrp "group" "directory" --- Changes the group ownership of a file or directory.
- chmod "..." "directory" --- Changes the read, write, and execute permissions for a user or group.