Mastering User and File Management in Linux

Introduction

Managing users and files efficiently is a cornerstone of system administration in Linux. 🖥️🔧 This blog delves into the essential aspects of user and file management, ensuring you can effectively control access, maintain security, and organize your data.

  • User Management involves creating, modifying, and deleting user accounts, assigning permissions, and managing groups. It ensures that each user has the right level of access to system resources and can perform their tasks without compromising the system's security.

  • File Management covers creating, organizing, and maintaining files and directories. It includes setting permissions, managing file ownership, and ensuring data integrity. With the right file management practices, you can keep your system organized, secure, and efficient.

System level commands

  1. Shows the platform name of the cli( command line interface).

     uname
    
  2. Screen time with users active.

     uptime
    
  3. Shows the date.

     date
    
  4. Shows the user logged in with time and data.

     who
    
  5. Shows only the user name only.

     whoami
    
  6. Show users id's and their group id's.

     id
    
  7. It refers to the super user or root user for the file access permission.

     sudo
    
  8. Shutdown and reboot the system or instance.

     sudo shutdown #shutdown
     sudo reboot   #reboot
    
  9. To install an application.

     sudo apt install 'application name' # finding the application  in system and download it
     sudo apt-get install 'application name' # It is like installing an application from a browser
    
  10. Updates the application to install the applications.

    sudo apt-get update
    

Note: There are many package managers like this apt for Ubuntu,rpm for Red Hat, dnf for Fedora, portage foe centos, ect.

Users and group management commands

  1. To add a new user (-m stands to make user).

     sudo useradd -m 'username'
    
  2. To set the password to the new user.

     sudo passwd 'username'
    
  3. Switch to new user.

     sudo su 'username'
    
  4. To come in primary user or original user.

     exit
    
  5. To delete the user.

     sudo userdel 'username'
    
  6. To create groups.

    (Let's consider there are 2 groups Developers and Interns. Developers have 2 members d1 and d2. Interns have 3 members i1 i2,i3 respectively)

    (-a stands to add flag and -m for multiple )

     # create the groups of developers and interns
     sudo groupadd developers
     sudo groupadd interns
     # to add members in these groups (method 1 adding one by one)
     sudo gpasswd -a d1 developers
     sudo gpasswd -a d2 developers
     sudo gpasswd -a i1 interns
     sudo gpasswd -a i2 interns 
     sudo gpasswd -a i3 interns
     # to add members in these groups (method 2 adding the above members in respectively groups)
     sudo gpasswd -m d1,d2 developers
     sudo gpasswd -m i1,i2,i2 interns
    
  7. To delete group

     sudo groupdel 'groupname'System level commands
    

File permission commands

(Before understanding the file permission command please refer the below image thoroughly )

chmod Cheatsheet : r/linux

So, the above table says that drwxrwxrwx here d stands for directory and rwx represents read, write, and execute the file for user, group, and others respectively

  1. Change mode for the file permissions.

     chmod 764  newfile.txt # 7 for user  (read,write and execute)
                            # 6 for group (read,write ,no execute)
                            # 4 for other (only read)
    

    _rwxrw_r__ This represents the file permission of file newfile.txt remember to use command ls -l will show the file and directory permissions

  2. To change ownership belongs to a file or directory.

     sudo chown 'username' newfile.txt
    
  3. To change a group belongs to a file or directory.

     sudo chgrp 'groupname' newfile.txt
    

Compression commands

  1. To zip the file or directory.

     zip 'zipfilename.zip' 'path/ / '
    
  2. To unzip the file or directory.

     unzip 'zipfilename.zip'
    
0
Subscribe to my newsletter

Read articles from Kiran Ramakrishna Dunka directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kiran  Ramakrishna Dunka
Kiran Ramakrishna Dunka