Mastering Linux User Management & File Permissions

padam sinhapadam sinha
4 min read

Linux is a robust and versatile operating system, widely used for its security, efficiency, and flexibility. A crucial aspect of managing Linux systems is understanding user management and file permissions. This blog will cover essential commands and concepts in this area, complete with examples.

System-Level Commands

uname

The uname command provides information about the platform you're connected to.

uname -a

Example Output:Linux hostname 5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

uptime

The uptime command shows how long the system has been running and the number of users currently logged in.

uptime

Example Output:12:34:56 up 10 days, 3:21, 2 users, load average: 0.00, 0.01, 0.05

date

The date command displays the current date and time in UTC format.

date

Example Output:Wed Jul 8 12:34:56 UTC 2020

who

The who command lists users currently logged into the system.

who

Example Output:username tty7 2020-07-08 12:34 (:0)

whoami

The whoami command prints the current username.

whoami

Example Output:username

which

The which command shows the location of the executable file for a given command.

which ls

Example Output:/bin/ls

id

The id command displays the user ID (UID), group ID (GID), and groups of the current user.

id

Example Output:uid=1000(username) gid=1000(username) groups=1000(username),27(sudo)

sudo

The sudo command allows a permitted user to execute a command as the superuser or another user.

sudo shutdown -h now

Example Output: This will shut down the system immediately.

reboot

The reboot command restarts the system.

sudo reboot

apt

The apt command is used as a package manager to install, update, or remove software.

sudo apt update
sudo apt install htop

apt-get

The apt-get command is another package manager command similar to apt the only difference is that it brings the packages from the internet.

sudo apt-get update
sudo apt-get install htop

yum, dnf, pacman, portage

These are package managers for different Linux distributions (e.g., CentOS, Fedora, Arch Linux, and Gentoo).

User & Group Management Commands

useradd

The useradd command creates a new user. Requires sudo permissions.

sudo useradd newuser

passwd

The passwd command sets or changes a user's password. Requires sudo permissions for other users.

sudo passwd newuser

su

The su command switches to another user.

esu newuser

userdel

The userdel command deletes a user. Requires sudo permissions.

sudo userdel newuser

groupadd

The groupadd command creates a new group. Requires sudo permissions.

sudo groupadd newgroup

groupdel

The groupdel command deletes a group. Requires sudo permissions.

sudo groupdel newgroup

File Permission Commands

File permissions are crucial for securing and managing files. Permissions are displayed in the format drwxrwxr-x.

Breakdown of Permissions

  • d: Directory (if present)

  • r: Read

  • w: Write

  • x: Execute

ls -l

Example Output:drwxrwxr-x 2 user group 4096 Jul 8 12:34 folder

  • drwxrwxr-x: Directory with read, write, and execute permissions for the owner and group, and read and execute permissions for others.

umask

The umask command sets default permissions for new files and directories.

umask 022

chown

The chown command changes the ownership of a file or directory.

sudo chown newuser:newgroup file

chgrp

The chgrp command changes the group ownership of a file or directory.

sudo chgrp newgroup file

Compression Commands

zip

The zip command compresses files into a .zip archive.

zip archive.zip file1 file2

unzip

The unzip command extracts files from a .zip archive.

unzip archive.zip

tar

The tar command creates and extracts .tar archives.

tar -cvzf archive.tar.gz folder // to compress
tar -xvzf archive.tar.gz // to extract

File Transfer Commands

scp

The scp command securely copies files between local and remote systems.

scp file user@remote:/path

rsync

The rsync command synchronizes files and directories between local and remote systems.

rsync -avz file user@remote:/path

Conclusion

Understanding and utilizing these commands is essential for effective Linux system management. They provide the tools to manage users, groups, file permissions, and more, ensuring a secure and efficient environment.

Feel free to connect and share your thoughts or additional tips! #Linux #CommandLine #SystemAdministration #OpenSource #UserManagement #FilePermissions #TechLearning #LearningInPublic

0
Subscribe to my newsletter

Read articles from padam sinha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

padam sinha
padam sinha