Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from stackoverflow.com Sep 3 '12 at 20:08

This question came from our site for professional and enthusiast programmers.

1  
try sudo su. Not sure what is the difference – balki Sep 1 '12 at 14:28
    
same question on unix&linux: unix.stackexchange.com/q/46904/4667 – glenn jackman Sep 1 '12 at 15:00

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.

share|improve this answer
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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .