Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

sudo

Sudo

su requires root password and launches a new shell. su creates a new shell that will make determining who ran the command difficult. sudo requires current user password, and user must be in visudoers. sudo commands are logged and tagged to the user. sudo is the default on Ubuntu, but not all linux systems.

su

as root, to assign pass. cant login as root until pass created. This is normally not the way you want to become root because it doesn’t transfer the proper environment variables. Ubuntu recommends against setting root password and allowing root to login directly.

How to Add to Sudoer

(one way)

su -c 'visudo'
user    ALL=(ALL:ALL) ALL

(A better way)

sudo adduser <someuser>
sudo usermod -aG sudo <someuser>

rerun command

sudo !!

If you need to rerun your last command, but as su instead

switch and use

su <user> -c <command>

Run command after switching to the target user, using their environment

Full root Shell

sudo -i

Root w/Environment

To become root, and get the right environment. This is almost always the way you want to be root.

su - 

User Troubleshooting

sometimes, you want to become a user to see things as that user sees them, debug, etc. This is not the way to install and run your system because you end up giving the user root permissions during their login like this. This could have very bad results! Use it for troubleshooting only.

su - <user> or su -l <user>

Root w/o Password

Allows you to drop to a new root shell, without knowing root password.

sudo su 

Same effect, that it uses the user environment

sudo -iu user / sudo su user

/root

sudo -s 

does not read any environment variables, puts you in /root instead of /home/user