Stuff to review#

Info docs#

What is prettier info with vim keybindings, highlighted hypertext links, etc?

pinfo ls

Terminal#

How do I identify my current terminal device file?

tty
[root@rhel9-a ~]# tty
/dev/pts/0

Login#

Alternative way to login to root shell?

sudo -i  # preferred
# or
sudo su -

User's & Groups#

How to prevent login's from all user's except root?

Create /etc/nologin. See man pam_nologin.

What's a useful way to see members of a group?

groupmems -g wheel -l

Filesystems#

What's the man page for the File system Hierarchy Standard (FHS)?

man 7 file-hierarchy

How do I show all currently mounted filesystems?

mount
# or
findmnt

How do I show available disk space on mounted devices?

df -Th

File perms#

How do I apply SUID?

chmod u+s

How do I apply SGID?

chmod g+s

How do I set the sticky bit?

chmod +t

File operations#

How do I copy all files regular and hidden while preserving file attributes?

cp -a /somedir/. .

Text processing#

How do I print a specific line number from a file?

sed -n 5p /etc/passwd

How do I delete a line based on a specific line number?

sed -i -e '2d' file

How do I sort output numerically by column?

ps aux | sort -k4 -rn

How do I print specific columns by field delimiter?

cut -d: -f1 /etc/passwd

What's another way I can print a specific column by field delimiter?

awsk -F: '{ print $4 }' /etc/passwd

How do I search for a string and print a specific field (column) for any matches from a file?

awk -F: '/user/ { print $4 }' /etc/passwd

Booting#

3 way's to shutdown the system?

  1. halt or systemctl halt
  2. poweroff or systemctl poweroff
  3. reboot or systemctl reboot

How do I force an emergency reset a misbehaving system?

From a root shell run:

echo b > /proc/sysrq-trigger

How do I set the default boot target?

systemctl set-default multi-user

How do I reset the root password or recover a system that won't boot due to corrupted /etc/fstab?

  1. Press F12, ESC (or anykey?) to intercept countdown and enter GRUB2 menu.
  2. Highlight desired kernel entry and press e to edit.
  3. Append rd.break to the end of the kernel line that starts with linux. This tells the bootloader to break after initial ramdisk (rd) is loaded into memory.
  4. Press Ctrl-x to boot into a switch_root prompt. The system mounts the root fs read-only on /sysroot.
  5. Remount the root fs in read/write: mount -o remount,rw /sysroot
  6. Change root into /sysroot: chroot /sysroot
  7. Enter a new password for root: passwd Or edit /etc/fstab or do whatever other fixes are needed... vi /etc/fstab
  8. Create .autorelabel to force SELinux relabeling on all files next boot: touch .autorelabel
  9. Exit the chroot environment: exit
  10. Exit the switch_root prompt: exit

RHEL: How to change a forgotten or lost root password

System logging#

How do I configure persistent journal logging?

mkdir -p /var/log/journal
journalctl --flush