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
Shows the platform name of the cli( command line interface).
uname
Screen time with users active.
uptime
Shows the date.
date
Shows the user logged in with time and data.
who
Shows only the user name only.
whoami
Show users id's and their group id's.
id
It refers to the super user or root user for the file access permission.
sudo
Shutdown and reboot the system or instance.
sudo shutdown #shutdown sudo reboot #reboot
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
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
To add a new user (-m stands to make user).
sudo useradd -m 'username'
To set the password to the new user.
sudo passwd 'username'
Switch to new user.
sudo su 'username'
To come in primary user or original user.
exit
To delete the user.
sudo userdel 'username'
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
To delete group
sudo groupdel 'groupname'System level commands
File permission commands
(Before understanding the file permission command please refer the below image thoroughly )
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
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 commandls -l
will show the file and directory permissionsTo change ownership belongs to a file or directory.
sudo chown 'username' newfile.txt
To change a group belongs to a file or directory.
sudo chgrp 'groupname' newfile.txt
Compression commands
To zip the file or directory.
zip 'zipfilename.zip' 'path/ / '
To unzip the file or directory.
unzip 'zipfilename.zip'
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