Tuesday 11 June 2013

Change Default Users Home Directory

By default base directory for the system user is set to /home directory. I'd like to add user to /ghar/${user} directory instead of the default /home. How do I force useradd command to add user to /ghar under CentOS / RHEL / Fedora Linux server?

Default values for account creation defined in /etc/default/useradd file under CentOS / RHEL / Fedora / Debian / Ubuntu and other Linux distros. Simply open this file using a text editor, type:
 

# vi /etc/default/useradd

 # useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

 The default home directory defined by HOME variable, find line that read as follows:
HOME=/home
 
Replace with:
HOME=/ghar

Save and close the file. Now you can add user using regular useradd command:


[root@linux ~]# useradd testuser

[root@linux ~]# finger testuser

Login: testuser                   Name: (null)
Directory: /ghar/testuser               Shell: /bin/bash
Never logged in.
No mail.
No Plan.

No comments:

Post a Comment