❤️ ABS is one of the five Certified Kubernetes Service Providers in India ❤️

Linux User Creation, Permissions, chmod, and chown: A Comprehensive Guide

In this blog, we will delve into the fundamentals of user management, permissions, and two essential commands, chmod and chown, that empower you to exercise precise control over access and ownership of files in a Linux system.

User Creation and Management

User management in Linux is pivotal for maintaining a secure and organized environment. Here’s how you can create and manage users:

Create a User

To create a new user, utilize the useradd command followed by the desired username:

				
					sudo useradd newuser
				
			

To set a password for the new user, use the passwd command:

				
					sudo passwd newuser
				
			
Modify User Properties

User properties, such as username, home directory, and group, can be easily modified using the usermod command:

				
					sudo usermod -l newusername oldusername  # Change username
sudo usermod -d /new/home/directory newusername  # Change home directory
sudo usermod -g newgroup newusername  # Change group

				
			
Delete a User

To delete a user, use the userdel command:

				
					sudo userdel username

				
			
Permissions in Linux

Linux employs a sophisticated permission system to control access to files and directories. There are three types of permissions: read (r), write (w), and execute (x), and they are assigned to three categories: user (owner), group, and others. Here’s how to view and modify file permissions:

View Permissions

To view the permissions of a file or directory, utilize the ls command with the -l option:

				
					ls -l filename

				
			

This command will display a detailed list of permissions and ownership.

Modify Permissions with chmod

The chmod command enables you to change file permissions and follows a simple syntax:

				
					chmod [permissions] [file]

				
			

Permissions can be specified using symbols (e.g., +r for adding read permission) or in numeric format (e.g., 644 for read and write permission for the owner and read-only for the group and others). For example:

				
					chmod +x filename   # Add execute permission to a file
chmod 755 filename  # Owner: rwx, Group: r-x, Others: r-x

				
			
Ownership with chown

Ownership pertains to the user and group that have control over a file or directory. The chown command allows you to change ownership:

Change Owner

To change the owner of a file, use the following syntax:

				
					chown [newowner] [file]

				
			

For example, to change the owner of file.txt to newuser:

				
					chown newuser file.txt

				
			
Change Group

To change the group of a file, use the -c option with chown:

				
					chown :newgroup file.txt

				
			
Conclusion

In Linux, user creation, permissions, chmod, and chown are integral aspects of maintaining a secure and organized system. Properly managing users, understanding permissions, and effectively utilizing these commands will empower you to exert control over access and ownership of files and directories. By adhering to these guidelines, you can ensure the security and organization of your Linux environment.