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