Home  >  Article  >  Operation and Maintenance  >  How to change user information in Linux system

How to change user information in Linux system

PHPz
PHPzOriginal
2024-02-25 09:27:17769browse

How to change user information in Linux system

Title: Linux system user information modification steps and code examples

In the Linux system, user management is a very important task, including creating, modifying and deleting users wait. This article will introduce the specific steps on how to modify user information in a Linux system, and give corresponding code examples to help readers better understand and master related operations.

1. Steps to modify user information:

  1. Log in to the system: First, log in to the Linux system using an administrator account to modify user information.
  2. View user information: Enter the following command in the terminal to view all user information in the current system:

    cat /etc/passwd
  3. Modify user information: use the following command Modify the user's information, where 'user_name' is the user name of the user to be modified. You can modify the corresponding information content as needed.

    • Modify the user's password:

      sudo passwd user_name
    • Modify the user's home directory:

      sudo usermod -d /new_home_directory user_name
    • Modify User's Shell:

      sudo usermod -s /bin/bash user_name
    • Modify the user's display name:

      sudo usermod -c "New Name" user_name
    • Modify the user's group:

      sudo usermod -g new_group user_name
  4. Confirm modification: After modifying the user information, you can check the user information again to confirm whether the modification was successful.
  5. Exit the system: After completing the modification of user information, use the 'exit' command to exit the administrator account and switch back to the ordinary user account.

2. Code example:

Suppose you want to modify the home directory of user 'john' to '/home/john_new', you can follow the following steps:

  1. Use the administrator account to log in to the system.
  2. Execute the following command to modify the home directory of user 'john':

    sudo usermod -d /home/john_new john
  3. Confirm whether the modification is successful. You can use the following command to view the information of user 'john' :

    cat /etc/passwd | grep john
  4. Exit the administrator account and switch back to the normal user account.

Through the above steps and code examples, readers can learn how to modify user information in the Linux system, and at the same time strengthen their understanding and application of user management. I hope this article can help readers better use Linux systems for user management.

The above is the detailed content of How to change user information in Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn