I used my super user hoping that I will be able to do everything with it, but to access one directory, I still had to do sudo su command to switch to root because I was getting access denied. Then how come super user is super user and still can’t access directory? And if I was switching to root, why sudo su didn't ask for password for root user and it worked without or with super user password which wasn't allowed to execute dir?

  • My pathlld bash script will help you answer this question. See github.com/waltinator/pathlld.git - Bash script to answer "Why can't I read/write that file?" – waltinator Mar 15 '18 at 13:43
  • 2
    root is superuser. Everybody else can merely become root. – muru Mar 15 '18 at 14:30

Superuser and root are synonyms. Your user is probably a sudoer, not a superuser.

In Ubuntu, you can perform a single command as root using the sudo command. Or you can open a root’s shell using sudo su, sudo -s or sudo -i. (I won’t discuss the differences here. Also, plain su could be used – if you knew the root’s password.)

sudo cd makes no sense since it would change the directory and then drop to your shell which might not be able to open the directory. Therefore Ubuntu disallows it completely:

$ sudo cd /root
sudo: cd: command not found

However, we can issue:

$ sudo ls -l /root
total 0

So how can we cd to the directory? We have to use a root shell:

$ sudo su
root@my-ubuntu:/home/mirek# cd /root
root@my-ubuntu:~# ls -l
total 0

You asked why you haven’t to input password in this case. It’s because you have used sudo recently. To force it to need the password again, you can issue sudo -k. Otherwise, it starts to require the password after a few minutes again.

  • Thanks for clear explanation. But then why do I need to use sudo in the first place if I already am super user? I mean I logged in with super user called “developer” which has SU privilegies. – Limpuls Mar 15 '18 at 14:41
  • 1
    @Limpuls you are not the super user. developer is not the super user. Only root is. developer can become the superuser, i.e., root using su (or sudo). – muru Mar 15 '18 at 14:42
  • 1
    @Limpuls - see help.ubuntu.com/community/RootSudo – Panther Mar 15 '18 at 14:44
  • @Limpuls Adding to what muru said, your developer user is a sudoer, i.e. a user allowed to run sudo. Only root should be called a superuser. – Melebius Mar 15 '18 at 14:45
  • 1
    @Melebius Okay now I understand. So when we give privilegies to user and make him sudoer, he is allowed to use sudo command. Meaning that simple users by default can’t usd sudo command? – Limpuls Mar 15 '18 at 21:45

You can't run the cd command with sudo or else you will get errors. You must run:

sudo su


sudo -s

to get into a root shell before using cd as root.

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.