Security
cancel
Showing results for 
Search instead for 
Did you mean: 

Can I change root's home directory?

SOLVED
Go to solution
Linda Card
Frequent Advisor

Can I change root's home directory?

I hate to even ask this question. I was raised in unix that you do not ever change root's home dir or root's shell. However, I cannot find any reference to prove this. My predecessor has already changed root's shell to bash and it does seem to be working.

So I ask you experts, is it possible to change root's home dir (like say to /root) and move all his . files over to /root. Would it screw things up?

Thank you in advance
6 REPLIES
Ivan Ferreira
Honored Contributor
Solution

Re: Can I change root's home directory?

You can safely change the root home dir to another, for example /root, as long as this directory is in the "/" file system. The shell can also be safely changed as long is in /bin or /sbin, this is because if you start in single user mode, no other file system besides / is mounted, so you need your home and shell under the / file system.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Linda Card
Frequent Advisor

Re: Can I change root's home directory?

I thought that I was OK on this. We need to make this upgrade at several sites without qualified SAs so I have to be able to script it.
I changed the /etc/passwd file to show /root as root's home dir. I tar'd up the .files from / and put them over in a new directory called /root. After the reboot, I opened an xterm window and did pwd and I was in /, not /root.
I went to App Manager - System Admin - Daily Admin - Account Manager and clicked on root. I noticed that the Acct Mgr still had root's home dir as /. I made the change in Acct Mgr to root's home dir being /root and rebooted. When I logged in again as root, my home dir was /root. That is good.

So where was the home dir name stuck as / (slash)? I need to be able to script it. I really do not want rookies navigating down in Account Manager. I thought that the only place that held the home dir was /etc/passwd.
And ideas would be helpful.
Thanks in advance.
Ann Majeske
Honored Contributor

Re: Can I change root's home directory?

How did you change /etc/passwd? There is an optional auxiliary version of the /etc/passwd database that can get created, most often by vipw. These /etc/passwd.pag and /etc/passwd.dir files contain a database with the information from /etc/passwd in a format that speeds up access. But, if you just edit the /etc/passwd file with a generic editor they do not get updated. So, if the /etc/passwd.pag and /etc/passwd.dir files exist on your system you have 3 choices for editing the /etc/passwd file:
1) delete the /etc/passwd.pag and /etc/passwd.dir files and use the editor of your choice on /etc/passwd
2) use vipw to edit /etc/passwd
3) use the editor of your choice to edit /etc/passwd and then use the /sbin/mkpasswd command to update the /etc/passwd.pag and /etc/passwd.dir files.

Ann
Ivan Ferreira
Honored Contributor

Re: Can I change root's home directory?

You can try with a script like this:

for FILE in `ls /etc/passwd*`
do
sed "/^root/ s/:\/:/:\/root:/" $FILE > $FILE.modified
# cp $FILE.modified $FILE
done


After ensuring that $FILE.modified was correctly generated, uncomment the cp line.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Heironimus
Honored Contributor

Re: Can I change root's home directory?

root's default shell is a static binary on most systems to minimize dependencies during emergencies. "Normal" shells may be dynamic and won't work if any of the necessary shared libraries aren't available (like if they're on a filesystem that isn't mounted). That's part of why conventional wisdom says to leave root's shell alone.
Ivan Ferreira
Honored Contributor

Re: Can I change root's home directory?

Heironimus has a good point. As long as the shared libraries are on the same file system, you can use it, for example:

# ldd /bin/sh

Main => /bin/sh
libc.so => /usr/shlib/libc.so
# ldd /bin/ksh

Main => /bin/ksh
libc.so => /usr/shlib/libc.so
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?