how to access homedir by root user

I want to access root user's home directory /root/. However following commands dont lead me to the root directory.

sudo -s

cd ~

It leads to the home dir of regular user. How to access /root when using sudo -s to login as root. I am using bash4 on ubuntu12.04.

2

4 Answers

Use the command:

sudo -i

To start in interactive session as root, which is treated as a login shell. This will set the HOME environment variable appropriately.

Try cd /root.

~ is normally just a shorthand for the home directory, so if you are the regular user person then cd ~ is the same as cd /home/person.

sudo -s

lets you to execute a command as another user (sudo)

Basically, you are still logged in with your regular user but that one single command after -s is executed by another user (root in your case).

$sudo -s ls -l // you are root on this line
$cd ~ // you are regular user on this line

This is the reason why you are getting redirected into the home of your regular user.

Doing such things in general is a bad idea, this is why Ubuntu disabled such forms of root login.

If you could give us a hint what do you want to achieve, somebody may figure out how to solve that without substituting your regular user shell with a root shell.

sudo su - root

su will switch the user

However you need to specify the user you wish to switch too e.g. - root

Root will be used as default if you don't specify the user

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like