How to change into directory owned by root if I have sudo?

Bla*_*man 4 command-line sudo cd-command

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
Run Code Online (Sandbox Code Playgroud)

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

vid*_*rlo 10

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.
Run Code Online (Sandbox Code Playgroud)

[...]

 -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.
Run Code Online (Sandbox Code Playgroud)

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


Flo*_*sch 8

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

Use

sudo -i
Run Code Online (Sandbox Code Playgroud)

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

If you don't need root privileges anymore use

exit
Run Code Online (Sandbox Code Playgroud)

or Ctrl-D to exit the root shell.