Skip to content

Instantly share code, notes, and snippets.

@ejlp12
Last active April 5, 2021 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejlp12/2ed78784db4cbc097c0e4f05224107fe to your computer and use it in GitHub Desktop.
Save ejlp12/2ed78784db4cbc097c0e4f05224107fe to your computer and use it in GitHub Desktop.
**** RHCSA NOTE ****
==== Basic access
ssh-keygen
ssh-copy-id <servername>
==== Diagnostic Information
sosreport
==== File System Hierarchy, File Management
man hier
cp, rm, mv, mkdir, pwd, touch
ls -l ---> Hard link
ln -s ---> Soft link
====
groupadd <group-name>
useradd <user-name> -G <group-name>
useradd <user-name> -s /bin/nologin -G <group-name>
mkdir /shared
chown :mygroup /shared
chmod g+s /shared OR chmod 2775 /shared
==== Basic command
mkdir /tmp/bobs_files
find / -user bob | xargs -I {} cp {} /tmp/bobs_files/
find / -user julia -exec cp {} /root/findresults \; ---> Better/simple way
grep xyz /tmp/test-log-file > /tmp/matching-log-entries
tar -zcvf /tmp/log_archive.tgz /var/log
==== Access File control list
touch /tmp/acl_file
chown bob:bob /tmp/acl_file
setafcl -m u:larry:rwx /tmp/acl_file
setafcl -m u:curly:rwx /tmp/acl_file
setfacl -m u:moe:- /tmp/acl_file
setfacl -m g:mygroup:rw /tmp/acl_file
getfacl /tmp/acl_file
==== SELinux
setenforce enforcing
vi /etc/selinux/config (SELINUX=enforcing)
==== Process Management
====== Single process signal
kill -HUP <PID>
kill -TERM <PID>
kill -KILL <PID> = kill -9 <PID>
====== Multiple process signal
pkill -<SIGNAL> -U <username/UID>
pkill -<SIGNAL> -t <terminal>
pkill -<SIGNAL> -G <GUID>
pts/N is window terminal
ttyN is system console
search spesific process like `ps aux | grep ...`
pgrep -l -u <USER>
pstree <user>
pstree <pid>
pstree -np <user/pid>
====== Background job process
(while true; do echo "Hello " >> testfile; sleep 1; done) &
(while true; do echo "World " >> testfile; sleep 1; done) &
jobs
kill -<SIGNAL> %N
======= CPU scheduling priority (nice)
nice -<NUMBER> <command> (Number can be 0-19, root can be negative)
renice -<NUMBER> <pid>... (Can be multiple PID)
==== YUM
yum lit 'name*'
yum search <name>
yum search all 'name'
yum provides <dir_path>
yum info <name>
yum install <package>
yum upgrade <package>
yum remove <package>
yum group list
yum group info "name"
yum group install "name"
yum history
yum history undo <N>
tail -N /var/log/yum.log
yum repolist
yum repolist all
vi /etc/yum.repos.d/redhat.repo
yum-config-manager --enable <name>
yum-config-manager --add-repo=<url>
/etc/yum.repos.d/<name>.repo
[updates]
name=Red Hat Updates
baseurl=http://content.example.com/rhel7.0/x86_64/errata
enabled=1
gpgcheck=0
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
yum --enablerepo=reponame install <package>
yum update -y
==== File System
blkid
mount UUID="" /mountpoint
mount /deviceid /mountpoint
df -h
umount /mountpoint
fdisk /dev/vdb
partprobe /dev/vdb
gdisk /dev/vdb
partprobe /dev/vdb
mkfs -t xfs /dev/vdb1 ----OR---> mkfs.xfs /dev/vdb1
/etc/fstab
UUID=7a20315d-ed8b-4e75-a5b6-24ff9e1f9838 / xfs defaults 1 1 #Last number is dump flag and fsck order
mkswap /dev/vdbN
swapon /dev/vdbN
free
swapon -s
swapon -a (read /etc/fstab and mount all swap definition)
/etc/fstab
UUID=fbd7fa60-b781-44a8-961b-37ac3ef572bf swap swap pri=1 0 0
==== System Service
systemctl
systemctl --type=service
systemctl status <name>
systemctl list-units --type=service [--all]
systemctl stop <name>
systemctl start <name>
systemctl reload <name>
systemctl restart <name>
systemctl list-dependencies <name>
systemctl mask <name>
systemctl umask <name>
systemctl enable <name> (started at boot time)
systemctl disable <name>
systemctl poweroff
systemctl reboot
systemctl halt
systemctl list-dependencies <name>.taget |grep target
systemctl isolate <name>.target
systemctl get-default
systemctl set-default <name>.target
rescue.target
emergency.target
rd.break
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel
exit
exit
==== File system problem
boot to `emergency.target`, edit /etc/fstab
systemctl daemon-reload
==== Boot loader
/etc/default/grub
/etc/grub.d/
grub2-mkconfig > /boot/grub2/grub.cfg
grub2-install (reinstall boot loader)
==== Networking
ip addr show eth0
ip -s link show eth0
ip route
ss -ntulap
nmcli con add con-name "static-eth0" ifname eth0 type ethernet ip4 172.25.X.11/24 gw4 172.25.X.254
nmcli con mod static-eth0 ipv4.dns 172.25.254.254
nmcli con show --active
nmcli con up "static-eth0"
nmcli con mod "System eth0" connection.autoconnect no
nmcli con reload
/etc/sysconfig/network-scripts/ifcfg-eth0
hostnamectl set-hostname desktopX.example.com
hostnamectl status
nmcli con mod static-eth0 +ipv4.dns 172.25.254.253
nmcli con mod "System eth0" ipv4.ignore-auto-dns yes
host classroom.example.com
===== Logging
echo "*.debug /var/log/messages-debug" >/etc/rsyslog.d/debug.conf
systemctl restart rsyslog
logger -p user.debug "Debug Message Test" (Test logging)
journalctl -n 10
journalctl -p err
journalctl -f
journalctl --since today
journalctl --since "2014-02-10 20:30:00" --until "2014-02-13 12:00:00"
journalctl --since "9:00" --until "09:30"
journalcrl -b (since last boot)
/etc/systemd/journald.conf
mkdir /var/log/journal
chown root:systemd-journal /var/log/journal
chmod 2755 /var/log/journal
==== Time date
timedatectl
timedatectl list-timezones
timedatectl set-timezone Asia/Jakarta
tzselect (timezone selection)
timedatectl set-time 9:00:00
timedatectl set-ntp true
=== NTP
/etc/chrony.conf
systemctl restart chronyd
timedatectl set-ntp true
chronyc sources -v
==== Volume
fdisk /dev/vda
pvcreate /dev/vda2 /dev/vdb1
vgcreate vg-alpha /dev/vda2 /dev/vdb1
lvcreate -n hercules -L 2G vg-alpha
mkfs -t xfs /dev/vg-alpha/hercules
pvdisplay /dev/vda2
vgdispay vg-alpha
lvdisplay /dev/vg-alpha/hercules
=== extend volume
vgextend vg-alpha /dev/vdb2
pvmove /dev/vdb2
..OR..
vgreduce vg-alpha /dev/vdb2
lvextend -L +300M /dev/vg-alpha/hercules
lvextend -l +50%FREE
lvextend -L 768M /dev/finance/loans
xfs_growfs /mnt/hercules
resize2fs /dev/vg-alpha/hercules (for ext4)
lvcreate -n risk -L 128M finance
lvcreate -n <name> -L <size> <VG-name>
==== Cron Job
crontab -eu bob
18 15 * * * /bin/date >> /home/bob/stamp
==== Temp files
systemd-tmpfiles
/usr/lib/tmpfiles.d/*.conf
/run/tmpfiles.d/*.conf
/etc/tmpfiles.d/*.conf
systemd-tmpfiles --clean tmp.conf
systemd-tmpfiles --create gallifrey.conf
==== NFS
sudo yum -y install nfs-utils
sudo systemctl enable nfs-secure
showmount -e serverX
sudo mount -t nfs -o sync serverX:/share /mountpoint
/etc/fstab
serverX:/share /mountpoint nfs sync 0 0
sudo wget -O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/desktopX.keytab
serverX:/shares/public /mnt/public nfs sec=krb5p,sync 0 0
sudo mount -o sync,sec=sys serverX:/shares/manual /mnt/manual
=== automounting
sudo yum -y install autofs
sudo vim /etc/auto.master.d/demo.autofs
===== SAMBA
yum install cifs-utils samba-client
smbclient -L //serverX
mkdir -p /mountpoint
sudo mount -t cifs -o guest //serverX/share /mountpoint
sudo mount -t cifs -o username=watson //serverX/cases /bakerst/cases
sudo mount -t cifs -o credentials=/secure/sherlock //serverX/sherlock /home/sherlock/work
File content of /secure/sherlock:
username=username
password=password
domain=domain
vi /etc/fstab
//serverX/share /mountpoint cifs guest 0 0
======= NETWORKING
systemctl mask iptables
systemctl mask ip6tables
systemctl status firewalld
firewall-cmd --get-default-zone
firewall-cmd --set-default-zone public
firewall-cmd --permanent --zone=public --list-all
firewall-cmd --permanent --zone=public --add-port 8080/tcp
firewall-config #---> GUI for setting firewalld
firewall-cmd --permanent --add-service=httpd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment