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?
2 Answers
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.– LimpulsMar 15, 2018 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
usingsu
(orsudo
).– muruMar 15, 2018 at 14:42 -
1
-
-
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?– LimpulsMar 15, 2018 at 21:45
You can't run the cd
command with sudo
or else you will get errors. You must run:
sudo su
or
sudo -s
to get into a root shell before using cd
as root.
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?"