I have a deploy user that has sudo privledges.

I can't sudo cd into the directory, but I can list it like:

sudo ls /root

How can I cd into the folder, or is that not possible?


It is not possible, because sudo runs a single command as root; your shell is still owned by your user.

What you can do is to open a new shell as root, by running sudo -i or sudo -s. From man sudo:

 -i, --login
               Run the shell specified by the target user's password data-
               base entry as a login shell.


 -s, --shell
              Run the shell specified by the SHELL environment variable if
              it is set or the shell specified by the invoking user's pass-
              word database entry.  If a command is specified, it is passed
              to the shell for execution via the shell's -c option.  If no
              command is specified, an interactive shell is executed.

Either of these will give you a new shell, with root privileges, where you can freely change directory and run new commands as root.

| improve this answer | |

cd is a shell builtin command . You can't use it directly with sudo.


sudo -i

to get a root shell and then cd into the folder you want.

If you don't need root privileges anymore use


or Ctrl-D to exit the root shell.

| improve this answer | |

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