Blogs


Linux User Commands



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:

You can view the existing groups on your Linux operating system by entering the following Linux user commands:
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 john
The `-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 john
This 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.

Let's break down the permissions:
  • `u` stands for user/owner.
  • `g` stands for group.
  • `o` stands for others.
  • `a` stands for all (user, group, and others).

The symbols used for permissions are:
  • `r` stands for read.
  • `w` stands for write.
  • `x` stands for execute.
  • `+` to add a permission.
  • `-` to remove a permission.

Here are some common examples of using `chmod`:

1. Granting Read and Write Permissions to the Owner:
chmod u+rw file.txt
This command grants the user (owner) of `file.txt` both read and write permissions.


2. Revoking Write Permission from the Group:
   
chmod g-w file.txt
This command removes write permission from the group of `file.txt`.


3. Adding Execute Permission for Others:
   
chmod o+x script.sh
This command adds execute permission for others (users who are not the owner or in the group) to `script.sh`.


4. Setting Read and Execute Permissions for All:
   
chmod a+rw directory
This command sets read and execute permissions for everyone (user, group, and others) on the specified directory.


5. Numeric Representation of Permissions:

You can also use a numeric representation to set permissions. Each permission has a numeric value:
  •  `r` (read) is 4.
  •  `w` (write) is 2.
  •  `x` (execute) is 1.

For example, to give read and write permissions to the owner and read-only permissions to the group and others:
chmod 644 file.txt

Here, `6` corresponds to read (4) + write (2) for the owner, and `4` corresponds to read-only for the group and others.

Understanding and effectively using `chmod` is fundamental for managing file and directory permissions in a Linux system. It allows you to control who can read, write, and execute files, ensuring the security and integrity of your system.



Comments

Free Harvard Inspired Resume Template