Diary and notebook of whatever tech problems are irritating me at the moment.

20071224

Root ending up in the wrong home with sudo

On Ubuntu and some other distributions direct login to root is disabled and sudo has to be used. The idea is to discourage running as root as this is bad for security (just like running as administrator in Windows). It is possible to get to a root shell but there is a right way and wrong way to do it. The wrong way doesn't change the environment variables like $HOME which will cause programs like Midnight Commander to save their config files to the originating user's home directory but with root ownership.

This is the WRONG way which leaves $HOME still set to the originating user's home:

sudo -s (or) sudo /bin/sh

This is the correct way which sets $HOME to /root:

sudo su (or) sudo su - (or) sudo -i

To experiment, enter the above commands followed by "echo $HOME". Enter "exit" to return to the original shell.

No comments:

About Me

Omnifarious Implementer = I do just about everything. With my usual occupations this means anything an electrical engineer does not feel like doing including PCB design, electronic troubleshooting and repair, part sourcing, inventory control, enclosure machining, label design, PC support, network administration, plant maintenance, janitorial, etc. Non-occupational includes residential plumbing, heating, electrical, farming, automotive and small engine repair. There is plenty more but you get the idea.