Difference between revisions of "Change the home directory using usermod"

From PCLinuxOSHelp Knowledge Base
Jump to: navigation, search
(Create and layout New hotwo for Changing a current users home directory)
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Change the home directory using usermod ==
+
=== Change the home directory using usermod ===
 
 
 
This method is for command line warriors.
 
This method is for command line warriors.
  
Line 13: Line 12:
 
   * '''Change the home directory by editing /etc/passwd'''
 
   * '''Change the home directory by editing /etc/passwd'''
  
===Change the home directory by editing /etc/passwd===
+
=== Change the home directory by editing /etc/passwd ===
  
 
'''Alternatively you can also edit the /etc/passwd to change the home directory.'''
 
'''Alternatively you can also edit the /etc/passwd to change the home directory.'''

Latest revision as of 17:14, 27 January 2020

Change the home directory using usermod

This method is for command line warriors.

Before you use the usermod command the new home directory should be created, ownership should be assigned
to the new user and the folder should be chmoded correctly so that no one else can access it.

* Run the following commands to do it.
* mkdir /home/new_home_directory * chown username:username /home/new_home_directory * chmod 700 /home/new_home_directory * usermod --home /home/new_home_directory username * Change the home directory by editing /etc/passwd

Change the home directory by editing /etc/passwd

Alternatively you can also edit the /etc/passwd to change the home directory.

But you should be careful not to edit anything else.
Before editing this file it is always better to create the new home directory and assign proper permissions and ownership to it.

 * Execute the following commands.
* mkdir /home/new_home_directory * chown username:username /home/new_home_directory * chmod 700 /home/new_home_directory

Open the /etc/passwd file using a text editor and locate the line containing the required username it should look something like this username:x:500:500::/home/username:/bin/bash

NOTE: You must be ROOT to modify this file.

change it to:
username:x:500:500::/home/new_home_directory:/bin/bash

Example

From:
dwmoar:x:500:500:David M.:/home/dwmoar:/bin/bash

To:
dwmoar:x:500:500:David M.:/home/members/dwmoar:/bin/bash


Save the file. - Again you must be the ROOT user.


Finally copy all the old content to the new home directory

cp -f /home/username/* /home/new_home_dir/