System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

how to modify the root account (changing its home dir)

SOLVED
Go to solution
newa
Frequent Advisor

how to modify the root account (changing its home dir)

Hi

I wanted to change the home directory for the root accout from "/" to "/roothome"

I used usermod as follows and got a complaint:

****************************
$ id
uid=200(newa) gid=300(sa)
$ sudo /usr/sbin/usermod -m -d /roothome root
Login root is currently in use
****************************

All ideas on how to work around this?

Thanks a lot in advance.
4 REPLIES
newa
Frequent Advisor

Re: how to modify the root account (changing its home dir)

I know I can edit the /etc/passwd file ... but I prefer use "usermod" command if possible. Let me know if you don't think it's possible.
James R. Ferguson
Acclaimed Contributor

Re: how to modify the root account (changing its home dir)

Hi:

Use 'vipw' ... which is 'vi' wrapped with some lock protection for modifying the '/etc/password' file and some validity checking to make sure you do really mangle it.

Regards!

...JRF...
Bill Hassell
Honored Contributor
Solution

Re: how to modify the root account (changing its home dir)

This is much simpler using vi. Use these command:

mkdir /roothome
chmod 750 /roothome
chown root:sys /roothome
sudo vipw

Then edit the first line where the root user is listed and change :/: to :/roothome:
and save the result.

Now leave your current window open and start another window to login as root. If you can't login as root directly, you can probably use this:

sudo su - root

and that should login a new session. Then type pwd to verify your new $HOME directory. Now you can move all files in / to /roothome. Be sure to move (mv) the dot-files and dot-directories (/.profile, /.exrc, /.ssh, /Mail, etc) to /roothome. The / directory should only have directories, no files.

Now your system may have been compromised by unknowledgeable sysadmins or bad applications that stored files in /...you'll have to move those back as you discover them. Ideally you can get the error fixed so the application still works OK.

As all seasoned syadmins will tell you, / is never the right place for root's home, so /root or /roothome is a good choice.


Bill Hassell, sysadmin
newa
Frequent Advisor

Re: how to modify the root account (changing its home dir)

Did it. Thanks a lot