Linux Tools and Utilities: User and Group Management, File System Management, and Job Automation
Linux is a powerful operating system that provides many useful tools and utilities that can help you manage your system efficiently.
In this article, we will cover some important Linux topics like user management, group management, Linux file system permissions, archiving files in Linux, and job automation.
User Management
User management is an essential part of Linux system administration. Linux allows you to create and manage users and assign them various permissions.
Note: user1, user2, and user3
are sample names of users in the below table
Here are some common commands for managing users in Linux:
Commands | Description |
| Create user account |
| Assign user a password |
| Create a user account along with the user's home directory |
| Check user account properties |
| Check user password properties |
| Switch to user2 [ Press ctrl+d to exit from switched user] |
| Change the username of the existing user |
| Check the list of users on your system |
| Delete user account |
Group Management
In Linux, groups are used to manage access to system resources and files. Here are some common commands for managing groups in Linux:
Note: user1, user2, and user3
are sample usernames and group1
is the sample name of a group in the below table
Commands | Description |
| Create a group account |
| Add a single user to a group |
| Make a particular user the group admin |
| Add multiple users into a group |
| Remove the user from the group |
| Display a list of groups on the system |
| Check particular group account property |
| Check particular group admin property |
| Delete the group |
Linux File System Permissions
File system permissions are used to control access to files and directories. There are three types of permissions:
Basic permissions: Basic permissions are the traditional read, write, and execute permissions assigned to the owner, group, and others.
$ ls -l filename
[permissions] [link] [owner] [group] [filesize] [date&time_of_file] [Name_of_File]
Permissions: 10 characters
-|---|---|--- == Type|OwnerAttributes|GroupAttributes|PublicAttributes
Type :
- | d | c | l
: RegularFile|Directory|CharacterFile|symbolicLink Owner_attributes :Read|Write|Execute
Group_attributes :
Read|Write|Execute
Public_attributes :
Read|Write|Execute
Let's learn to change the permissions of the file:
chmod [option] [filename]
Options Type:
Character value:
[Option]---> [ who | what | which ] ---> [ u/g/o/a | -/+/= | r&/w&/x ]
For example,
chmod u+rwx filename
--------->Grants user with r+w+x access to the file.chmod g+rx filename
---------->Grants group with r+x access to the file.chmod a+x filename
----------->Grants user+group+others with x access.Numeric value
[Option]---> [ owner | group | other ] ---> [ 1...7 | 1...7 | 1...7 ]
For example,
chmod 700 filename
--------->Grants user with r+w+x access to the file.chmod 050 filename
---------->Grants group with r+x access to the file.chmod 777 filename
----------->Grants user+group+others with r+w+x access.
Special permissions: Special permissions are used to set advanced permissions for files and directories.
Let's learn to change the ownership of the file:
chown [option] [filename]
-----------------> Change user ownershipchgrp [option] [filename]
-----------------> Change group ownershipFor example,
Access control list (ACL) permissions: ACL permissions are used to grant specific permissions to individual users or groups.
If you want to give some read/write/execute permission to an outside user which is not a member of the group created by you. Then this can be done with ACL permissions
Commands
Description
getfacl [file/folder]
Check ACL permissions of file/folder
setfacl -m u:user1:rw [file/folder]
Set permissions for user
setfacl -m g:group1:rwx [file/folder]
Set permissions for group
setfacl -x u:user1: [file/folder]
Remove permissions for user
setfacl -x g:group1: [file/folder]
Remove permissions for group
setfacl -b [file/folder]
Remove all ACL permissions
In this case,
'chaitu
' is an outside user and not a member of the 'ubuntu
' group. Using ACL permissions 'chaitu
' has given 'read+write+execute
' access to a file 'backup.tar.gz
'.
Archive files in Linux
Archiving is a process of combining multiple files/ in one file. Archiving can be useful for backup purposes, or for transferring multiple files as a single unit.
tar [options] [archive_name.tar] [files/folders]
Options | Description |
-c | Create |
-x | Extract |
-v | Verbose |
-f | Forcefully |
-t | For test |
-z | For gzip |
-j | For bz2 |
-J | For xz |
-C | For specific location |
Here are some common commands for archiving files in Linux:
Commands | Description |
| Create Archive file |
| Extract tar archive file on default location |
| Extract tar archive file on specific location |
| Create Archive file with compress in size (gzip, bz2, xz) |
| |
| |
| Extract tar archive file (gzip, bz2, xz) on specific location |
| |
|
Check file size after you create archives: du -sh [ filename ]
Job Automation in Linux
Job automation in Linux is the process of automating repetitive tasks, jobs, or processes in Linux operating systems. Common tools used for job automation in Linux are
'
at
' command'cron' scheduler
Using 'at' command------->
at [ hh:mm ] [ month ] [ date ]
------------------------> Creates at job_____________________________________________________________________________________
For example:
at 4:40 Mar 27
warning: commands will be executed using /bin/sh at Mon Mar 27 04:40:00 2023
tar -czf backup.tar.gz /home/ubuntu/*
press ctrl+d
_____________________________________________________________________________________
atq
------------------------>Shows pending jobsatrm [ job_id ]
------------------------>Removes jobTo Restrict a particular user from accessing at utility edit at.deny file>>>>Just add username and save the file
_____________________________________________________________________________________
vim /etc/at.deny
krishiva
:wq
_____________________________________________________________________________________
krishiva:~$ at 10:37 Mar 20
You do not have permission to use at.
_____________________________________________________________________________________
Using 'cron' scheduler------->
You can create cron jobs using the cron scheduler Cron is a time-based job scheduler in Linux that allows you to schedule jobs to run at specific times or intervals.
Check cron package availability in the ubuntu system
$ dpkg -s cron | grep
Status Status: install ok installed
$ service cron start
------------------------>start your cron service$ systemctl enable cron.service
------------- >add to startup program$ service cron status
----------------------->shows cron service statusFollowing are commands for crontab utility:
$ crontab -e
----------------------->set a cron jobFor example:
crontab -e
______________________________________________
0 0 * * * tar -czf backup.tar.gz /home/ubuntu/*
:wq
______________________________________________
This crontab will create a compressed backup archive of all files and directories in the
/home/ubuntu
directory every day at midnight$ crontab -l
----------------------->list cronjobs of current usr$ crontab -r
----------------------->remove cron jobsOr go to
crontab -e
file and remove cronjob lines$ crontab -u chaitu -e
----------------------->set a cron job for other usr$ crontab -u chaitu -l
----------------------->list cronjobs of other usr$ service rsyslog restart
--------------------->Start rsyslog service to check logs$ tail -f /var/log/syslog
----------------------->check crontab log file$ tail -f /var/log/syslog | grep CRON
------------->check cron log entries onlyTo Restrict particular users from accessing at cron service edit cron.deny file>>>>Just add the username and save the file. _____________________________________________________________________________________
vim /etc/cron.deny
krishiva
:wq
_____________________________________________________________________________________
krishiva:~$ crontab -e
You do not have permission to use crontab.
_____________________________________________________________________________________
Summary:
In this blog, we covered important topics like user management, group management, Linux file system permissions, archiving files in Linux, and job automation. I hope this blog has been informative and helpful to you.
Stay tuned for my next blog on "Linux Advanced Features". I will keep sharing my learnings and knowledge here with you.
Let's learn together! I appreciate any comments or suggestions you may have to improve my Linux blog.
Thank you,
Chaitannyaa Gaikwad