Linux, with its robust and flexible nature, provides a powerful set of commands for user administration and management. Whether you're a system administrator or an enthusiast, understanding these commands is essential for maintaining a secure and efficient Linux system. In this tutorial, we'll explore key user-related commands, including creating and deleting users, managing user groups, using the 'finger' command, and changing user permissions.
1. Creating a User:
To create a new user, you can use the `useradd` command. The following example demonstrates how to create a new user named 'John' to show
sudo useradd john
You can also set a password for the new user using the `passwd` command:
sudo passwd john
2. Deleting and Disabling Accounts:
To delete a user account, you can use the `userdel` command:
sudo userdel john
To disable an account without removing it, you can use the `passwd` command with the `-l` option:
sudo passwd -l john
This locks the user account by replacing the encrypted password with a placeholder, preventing login.
3. Adding Users to User Groups:
groupmod "Press Tab key twice"Adding a user to a specific group is done using the `usermod` command. In this example, we add the user 'john' to the 'developers' group:
sudo usermod -a -G developers johnThe `-aG` options stand for append and group, ensuring the user is added to
the specified group without affecting existing group memberships.
4. Finger Command:
The `finger` command provides detailed information about users. To check information about the user 'john,' use the following command:
finger johnThis will display information such as the user's login name, real name,
terminal, login time, and more.
5. Changing User Permissions:
To modify user permissions, use the `chmod` command.
chmod option permissions file
- options: Optional flags that modify how the command behaves.
- permissions: The new permissions to set (e.g., u+rwx for user read, write, and execute).
- file: The file or directory for which you want to change permissions.
- `u` stands for user/owner.
- `g` stands for group.
- `o` stands for others.
- `a` stands for all (user, group, and others).
- `r` stands for read.
- `w` stands for write.
- `x` stands for execute.
- `+` to add a permission.
- `-` to remove a permission.
chmod u+rw file.txtchmod g-w file.txtchmod o+x script.shchmod a+rw directory- `r` (read) is 4.
- `w` (write) is 2.
- `x` (execute) is 1.
chmod 644 file.txt
Comments
Post a Comment