User and Groups
Root without asking password
<user_name> ALL=(ALL) NOPASSWD: ALL
/etc/sudoers Write logs
Defaults log_host, log_year, logfile="/var/log/sudo.log"
Run command with sudo without password
notify ALL=(ALL) NOPASSWD:path_to_command, path_to_command
sudo mount /dev/<device id> /mnt
chroot /mnt /bin/bash
passwd <user name>
sudo umount -l /mnt
Show real and effective user and group IDs
id
Show last logged users
last
Verifies the integrity of the users and authentication information.
pwck
Verifies the integrity of the groups information.
newgrp
Change shell of user
chsh
Show password expiration date
chage -l <user_name>
Restricted Shells
useadd <user name> –s /bin/rbash
mkdir –p /home/<user name>/bin
cp /bin/ping /home/<user name>/bin
ln –s /bin/ls /home/<user name>/bin
Create a user with defaul group and add him to other group.
useradd -m -N -g primary_group -G other_group user_name
Create system user
useradd --system --no-create-home -s /sbin/nologin user_name
Delete user
userdel <user name>
userdel –rf <user name>
Create group
groupadd group_name
Delete group
delgroup group_name
Make the default group
usermod -g group_name user_name
Add to the group
usermod -a -G group_name user_name
Remove user from group
usermod -R group_name user_name
Run shell as another user
sudo -iu user_name
sudo su - user_name command
sudo su user_name -s "/bin/bash"
Execute the previous command with sudo
sudo !!
Write command results to file with privileges
echo 1 | sudo tee -a privileged_file > /dev/null
Run shell as another user
su - user_name
su -l user_name
sudo su - user_name