How to I change into a directory owned by root?

If I do: sudo cd RootOwedDir

I get: sudo cd: command not found

If I su root

I get: authentication failure, probably because I never really set up an actual root account.

What am I doing wrong here?

  • To summarize: both cYrus's "sudo su" and "sudo sh -sc "cd dir_path" (note the additions 's' parm) solved the problem. Thanks to everyone for their help. – unknown google user Dec 12 '10 at 0:17

Instead try using sudo -s to start a root shell and then simply cd into the directory.
When you're done as root, press CtrlD or type exit.

It is important to note that as root, one can easily do damage to essential system components. Use with care!


That's because cd isn't a command but a built-in shell function; and su expects the root password. Simply use:

sudo su

to run a shell with root privileges. Type exit or press Ctrl + D to return to the previous shell when you're done.

  • 2
    sudo su is unnecessarily complicated. sudo -s makes sudo start a shell; or you can run sudo bash or sudo zsh if you don't want to have to remember the -s option. – Gilles 'SO- stop being evil' Dec 11 '10 at 23:06
sudo sh -c "cd dir_path"
  • This is not working for me either. It might be because the directory I want to enter has embedded spaces in the name. I have tried variations on sudo sh -c "cd my\ path" with no luck. No error message it just returns as if it did something but I remain in the same directory. sh is installed on my system though I normally use bash. – unknown google user Dec 11 '10 at 19:30
  • @unknown - I've always figured you'd have to spawn a subshell to run shell builtins as root, whether in bash or plain old sh. I'm determined to figure this out. – Wesley Rice Dec 11 '10 at 19:39
  • Adding the -s option along -c did the trick. Thanks for the effort. – unknown google user Dec 12 '10 at 0:19

You can also do a sudo vim on the folder, ie sudo vim RootOwedDir and it will show the vim view for folders, which will show all the files/folders that are in that folder. then you can just run what you need to from outside the folder, and sudo it just like normal.


su - then type in your password. You now can just cd into the directory. Remember tho you are now root so ctrl-d before you do anything you don't want to be root for.

  • That produces an authentication error on Ubuntu. – Wesley Rice Dec 11 '10 at 19:02
  • Really? I have never had an issue for me. – Unfundednut Dec 11 '10 at 19:06
  • 2
    For OP it would, certainly, as he doesn't doesn't have a proper root account. – Wesley Rice Dec 11 '10 at 19:15
  • Interesting, I am on a fresh install of Ubuntu, I never 'setup' a root user yet I can simply sudo - and bam I am god of the system. – Unfundednut Dec 11 '10 at 19:18
  • Yeah, I just get an authentication error. – unknown google user Dec 11 '10 at 19:23

For me a combination of sudo and screen worked out:

sudo -iu vagrant screen -mS npm_install bash -c 'cd /vagrant && npm install'

This command first switches to the vagrant user. Then as vagrant changes the directory to /vagrant and executes npm install.


The easiest way to do this is to enable the root account and use su to become root. Ubuntu is very protective of the root account due to the potential for misuse, but at times, it is much easier to use the root account rather than sudo on every line. Just be aware of what account you are using at any given time.

Taken from here:

Open the terminal and type: sudo passwd root. When you see the prompt that says “Enter new UNIX password”, enter the password you want for the root user and confirm it.

At this point, you will be able to change to root using su and cd to the directory.

  • -1. This is full of wrong. What does GDM have to do with anything? OP wants to 'cd' to a dir readable only by root. No one should ever log in as root via GDM. – Wesley Rice Dec 11 '10 at 21:11
  • Good point. I didn't fully read what I was pasting there. – zcid Dec 11 '10 at 21:14
  • Much easier than this is enabling a root shell with sudo -s as others have said, and much better than this is learning about sudo, a much more flexible and granular tool than su, if well used. – Adriano Varoli Piazza Nov 3 '11 at 21:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.