How To Change Existing User Home Directory In Linux
This cursory guide explains how to create home directory for existing user in Linux and Unix-like operating systems using mkhomedir_helper
command.
Introduction
Equally you know already, we tin create a new user in Linux and Unix-like systems using adduser
command, right? Yes, that's right! When we add a new user, the home directory for the respective user is automatically created by default.
There is also another command to create users in Linux. It is chosen useradd
.
After I created a few users using useradd
command in Alpine Linux, I noticed that the $HOME directories for the users are not created. I am non aware of it before.
Later on reading the useradd
control's homo pages, I came to realize that I should have included -k
(or --create-home
) option to create new users with $Home directory similar beneath:
$ sudo useradd -m user_name
Or,
$ sudo useradd --create-home user_name
But, I forgot to include this option and went on to create a few new users. If you lot are anything like me, don't delete the existing users and recreate them with -m
option.
You lot can easily create home directory for an existing user in Linux using mkhomedir_helper
control, without deleting and recreating the user.
Create Home Directory For Existing User In Linux
The mkhomedir_helper
is a helper program for the pam_mkhomedir
module. The pam_mkhomedir
PAM module will create a user'due south home directory if it does not be when the session begins.
Showtime, this module creates the habitation directories and so populates them with contents of the specified skel directory. The default value of umask
is 0022
and the default value of path-to-skel is /etc/skel
.
Allow me to bear witness you lot an example to explicate how to create the abode directory for an existing user with the assistance of mkhomedir_helper
command.
Start, let us create a new user named ostechnix using useradd
command:
$ useradd ostechnix
Set password to the user:
$ passwd ostechnix
Now switch to the new user:
$ su - ostechnix
Y'all will encounter with the following mistake bulletin:
su: warning: cannot change directory to /home/ostechnix: No such file or directory
Every bit you see in the to a higher place output, the home directory for the user ostechnix does not exists, hence this error.
Let us verify it by looking into the /habitation
directory:
$ ls -l /home/ total 0 drwx------ 1 vagrant vagrant 72 Dec 15 13:19 vagrant
Well, it is true that there is no domicile directory for the user ostechnix.
So permit usa create the home directory for the existing user (i.eastward. ostechnix in our case) with mkhomedir_helper
command.
To do so, first log out from the user ostechnix if you already logged in:
$ exit
And run the post-obit control to create dwelling house directory for the user chosen ostechnix:
$ sudo mkhomedir_helper ostechnix
Please note that you must run the above control as root
user or unlike sudo
user.
Now switch to the user ostechnix:
$ su - ostechnix
This fourth dimension yous will not go any warning message, because the home directory for the user called ostechnix has been created with mkhomedir_helper
command.
[[email protected] ~]$ pwd /habitation/ostechnix
For more than details, refer human pages:
$ man mkhomedir_helper
You lot know now how to create home directories after creating the users. This tin exist useful when you forgot to include -k
pick while creating users with useradd
command.
Instead of using useradd
, yous tin use adduser
control which will create user's home directories automatically without whatsoever options.
Featured paradigm past FreeCliparts from Pixabay.
Source: https://ostechnix.com/create-home-directory-for-existing-user-in-linux/
Posted by: phillipsnobjess76.blogspot.com
0 Response to "How To Change Existing User Home Directory In Linux"
Post a Comment