Skip to main content

Command Palette

Search for a command to run...

Linux - chapter-5: permissions and user commands

Managing Linux Users, Groups, and File Permissions commands

Updated
5 min read
Linux - chapter-5: permissions and user commands
B

Software Engineer

we need to know linux commands before diving into DevOps concepts, as a DevOps engineer, it is necessary to acquire linux commands as it is a first and foremost skill to start with,

There are different categories of Linux commands. In the previous chapter, we learned about data and editor commands. Now, in Chapter 5, we will dive deep into user permissions and search commands. I will split the Linux commands into individual articles instead of covering everything in a single article.

5th chapter is User permissions and Search Commands:

as the name suggests, user and search commands in Linux are commands used to manage users and groups on the system.

They help you:

  • Create or delete users

  • Change passwords

  • Switch between users

  • Control user permissions and groups

Copy data:

  1. cp: copy the complete data from one file to another file

  2. cp sourcefile destinationfile: copy the complete data from source file to destination file by overwritting the previous data

  3. cat >> filename: to append the data in the destination file

  4. cat source >> destination: used to add source file data to destination file by overwritting the previous data.

    there are 2 commands in this, cat source means to read the sourcefile content, and then \>> destination means to append the new data in destination file without overwritting the previous data.

  5. cat >> filename: to append the data in the destination file

Copy files in folder:

  1. cp sourcefiles destinationfolder: used to copy all the source files and paste those files in destination folder. (will be acts as ctrl+ c and paste)

  2. mv sourcefiles destinationfolder: used to cut all the source files and paste those files in destination folder. (will be acts as ctrl+ x and paste)

Rename files:

  1. mv sourceName destName: rename the existing file with new name.

Move back directory to root:

  1. mv fol2/fol1 ~/ :To move folder1 from folder2 back to the root directory, use the command: mv fol2/fol1 ~/.

copy file from existing directory to another directory:

  1. cp folder1/file1 folder2: copy file1 from folder1 to folder2.

  2. mv folder1/file1 folder2: move file1 from folder1 to folder2.

1. Permission commands:

  1. -rw-r--r--

    - represents type of the file(TBF - text based file)

    d directory

    r read => 4

    w write => 2

    x execute => 1

    last - no permission => 0

    we have to divide complete rw-r--r-- into 3 parts:

    1. rw- (read & write) first 3 will be called as user permissions = read = 4, write = 2, - = 0 => total = 6

    2. r— (read only permissions) next 3 will be called as group permissions

      read - 4, - = 0 => total = 4

    3. r— (read only permissions) last 3 will be called as others

      read - 4, - = 0 => total = 4

total: rw-r--r-- = 644

  1. whenever any system admin will see the permissions rw-r--r, then they will better understand it by decoding the value from it, that is total of 644, they can understand, user has read & write permissions, and group has read only permissions, and others has also read only permissions.

Change file permissions:

  1. chmod: used to change the permissions that is change mode

    to give full permissions for all users, = 777 (r-4, w-2, x-1)

  2. chmod 777 filename/ chmod 777 multifiles - to give complete permissions to complete file

  3. chmod +x filename = to give execute permissions to complete file.

  4. chmod 644 * = to give default permissions to all files

Change folder permissions:

  1. chmod 777 foldername/ chmod 777 multifolders - to give complete permissions to complete file

Change Folder Permissions and Apply Them to Files Inside Simultaneously:

  1. cmod 555 foldername -R: To change folder permissions, which also apply to the files inside the folder.

Change Permissions for Only the Files Inside a Folder:

  1. cmod 777 foldername/*: To change permissions for all files inside folder1, without affecting the folder itself, use the following command. This will apply the changes only to the files inside.

2. User Commands:

  1. cat /etc/passwd: to see list of users (-n to see numbered list)

  2. getent passwd: to see list of users (numbered list will not work here)

Create Users:

  1. adduser username or useradd username: to create new user

  2. id username: to see if user is created or not

  3. uid=1001(bhanu) gid=1001(bhanu) groups=1001(bhanu): When a new user is created, a new group is automatically created with the same user ID (uid) and group ID (gid).

  4. when a new user is created, a new path is also created for that user with tha username.

    user => group => path

Delete Users:

  1. userdel -r username: delete the user

navigate to user:

  1. su - username: to navigate to that user (su = switch user)

set password for user:

  1. passwd username: to add new password for that user

  2. while switching from root user to any user, it will not ask password though you’ve set it, because if you are in root user, it has every access and every permission, that is the reason.

3. Group commands:

Why do we need a group?

for sepecific users, we can create a common group and give file permissions to those specific users.

  1. cat /etc/group: to see list of groups(-n to see numbered list)

  2. getent group: to see list of groups

create group:

  1. groupadd groupname: to create a new group.

  2. usermod -aG groupname username (modify user to add to that groupname): to add list of users to any specific group.

  3. id username: To see if a specific user is in a group or to find out which groups a user belongs to.

delete user from that group:

  1. sudo gpasswd -d dev devops: delete user from specific group. (sudo = super user do, gpasswd = manage group accounts, -d = delete)

Linux Commands every DevOps engineer should know

Part 3 of 7

This series breaks down Linux commands into clear categories such as system, hardware, and file commands. Each topic is covered in a separate article to make learning Linux simple, organized, and beginner-friendly.

Up next

Linux - chapter-4: Data and Editor Commands

A Comprehensive Guide to Data and Editor Commands in Linux