The root account, user ID 0, is the administrator. The kernel does not check permissions for root: root can read, change and delete every file.
sudo: one command as root
sudo runs the command after it as root. Then you are your normal account again:
learner@tidepool:~$ whoami
learner
learner@tidepool:~$ sudo whoami
root
learner@tidepool:~$ cat /srv/shop/secret.txt
cat: /srv/shop/secret.txt: Permission denied
learner@tidepool:~$ sudo cat /srv/shop/secret.txt
safe code: 4471On Ubuntu, the members of the group sudo can use sudo. On a real server, sudo asks for your password first. In this course, it does not.
A root shell: sudo -i
sudo -i opens a shell that runs as root. The prompt ends with #. exit takes you back:
learner@tidepool:~$ sudo -i
root@tidepool:~# whoami
root
root@tidepool:~# exit
learner@tidepool:~$sudo and >
The shell prepares > before the command starts. So with sudo echo text > FILE, your shell opens the file, as your account, and fails:
Let a program that runs as root write the file. tee writes its standard input to a file:
learner@tidepool:~$ echo "Welcome to tidepool" | sudo tee /etc/motd
Welcome to tidepoolUse sudo tee -a to add to the end of the file.