5

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?

Zanna
  • 69,223
  • 56
  • 216
  • 327
Blankman
  • 8,095
  • 14
  • 38
  • 39

2 Answers2

11

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.

vidarlo
  • 21,954
  • 8
  • 58
  • 84
8

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

Use

sudo -i

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

If you don't need root privileges anymore use

exit

or Ctrl-D to exit the root shell.

Florian Diesch
  • 86,013
  • 17
  • 224
  • 214