How to change the default directory for users in Linux?

To change the default directory for Linux users, you can follow these steps:

  1. Log in to the system as the root user.
  2. Open the file /etc/default/useradd and make edits using a text editor such as vi.
  3. Open the useradd configuration file located at /etc/default/useradd using the vi editor.
  4. In the file, locate the line HOME=/home and modify it to the desired directory path.
  5. For example, change the default directory to /data:
  6. The home directory is set to /data.
  7. Save and close the file.
  8. You can use the usermod command to change the default directory of an existing user.
  9. Change the user’s home directory to /data.
  10. is the username of the user to be modified.
  11. To confirm if the modification was successful, you can use the grep command to check if the corresponding user’s directory in the /etc/passwd file has been changed.
  12. Search for in the /etc/passwd file.
  13. If the output directory in the result is already the modified directory, then the modification was successful.

Changing the default directory for users may cause some applications or scripts to not work properly, so it is important to carefully consider and back up the relevant data before making any modifications.

Leave a Reply 0

Your email address will not be published. Required fields are marked *