Last edit: October 01, 2017 09:56:12 AM CDT List of all cheatsheets See also *nix Config Files & System Config Network configuration files /etc/hosts /etc/init.d (even with systemd) /etc/resolv.conf (DNS servers and search domain) /etc/network (Ubuntu routing and host information for all interfaces) /etc/nsswitch.conf (Order of authentication and host lookup) /etc/systemd/ /etc/sysconfig/network (RHEL 5/6 routing and host information for all interfaces) /etc/sysconfig/network-scripts/ (RHEL 5/6system-wide interface configuration. User connection settings are saved in gconf configuration database and the Gnome keyring) /etc/sysconfig/networking (RHEL 5/6Used by GUI; don't hand edit) Name resolution /etc/hosts is local, /etc/resolv.conf is remote. Users & Groups /etc/passwd Boot control (RHEL) /etc/grub.conf Persistant kernel modules /etc/modprob.conf (RHEL 5) /etc/modprobe.d/local.conf (RHEL 6) Directory authentication information (RHEL) /etc/sssd/sssd.conf What services are running at boot systemctl list-units -t service Get timezone information timedatectl status Set the timezone timedatectl list-timezones timedatectl set-timezone zone What starts at boot (RHEL 5/6) chkconfig --list Files Change ACLs setfacl -m [u/g:group:scheme] /path Drives, Disk Images & File Systems Display information about device blkid List disk & partition information for all connected devices fdisk -l Specific information about a particular partition or drive fdisk -ul /dev/[disk] Get superblock information dumpe2fs -ob | grep -i superblock List connected disks lsscsi Basic clone with dd dd if=/dev/input/device-here of=/dev/output/device-here bs=128k conv=noerror,sync Clone to disk image dd if=/dev/da0 conv=sync,noerror bs=128K | gzip -c > path/to/output.gz Restore from disk image gunzip -c image.here-gz | dd of=/dev/output/device-here Mount a USB drive 1. fdisk -l 2. mkdir /mnt/newmnt 3. mount /dev/path /mnt/newmnt Or. mount -t [type=msdos|ext*|nfs|usbfs/vfat]/dev/[path] /mnt/newmnt Mount a CD mount /dev/sr0 /mnt/cdrom Procedure to create new partition 1. Use fdisk to create partition p: prints partition table n: create new w: write partition 2. mkfs -t [ext3|vfat|msdos| to put filesystem on partition 3. mkdir /new/mnt/dir to create mount point 4. Physical partition: mount -t [type] /path/to/mount or Logical partition: mount /dev/mapper/[path] /path/to/mount 5. Edit /etc/fstab Procedure to create new disk using parted 1. List partitions: parted -l 2. Format the disk: parted /dev/path/to/new mklabel gpt 3. Partition the disk (ext4): parted -a opt /dev/path/to/new mkpart primary ext4 0% 100% 4. Create the filesystem on disk: mkfs.ext4 -L [name] /dev/path/to/new 5. Prep the mount: mkdir -p /mnt/data 6. Mount the disk: Edit /etc/fstab Increase the disk space on a LVM volume on a VM 1. Increase the vmdk file size 2. fdisk -l to note where the added space is located (type is 8e) 3. Create a new parition that uses the added space fdisk /dev/sda, then: n (new) p (primary) # (partition number to assign starting with first available cylinder) t (type) # (partion number) 8e (set to LVM) p (view layout) w (write new layout) reboot 4. pvcreate /path/to/new/part 5. vgextend VolGroup### /path/to/new/part and confirm with vgdisplay 6. lvextend -l +100%FREE /dev/VolGrou##/LogVol00 7. resize2fs -p /dev/mapper/VolGroup[num] Make new swap space 1. fdisk -l to find device if needed 2. mkswap /dev/[path] 3. swapon /dev/[path] 4. Edit fstab: [dev/path] {part name} swap defaults 0 0 Fun with e2fsk (aka File System Utility) Check/clean filesystem - e2fsck Clean all - e2fsck -a Use an alternate superblock - e2fsck -b [block size number] Find badblocks - e2fsck -c and add to existing list: -k Force check - e2fsck -f To edit files while in maintenance mode mount -o remount, rw / Formatting for /etc/fstab device mount point type mount options dump & fsck dev/path /path ext/vfat/etc rw, ro, defaults, auto 0 0 Hardware & Kernel Get hardware, serial number and BIOS info dmidecode -s system-serial-number dmidecode -s system-manufacturer dmidecode -s system-product-name lshw Get OS release information lsb_release -a Get OS release information cat /proc/version Get kernel & hardware info uname -a List all PCI devices lspci -v Display information about installed hardware (Ubuntu) lsdevs Create System Profiler-like package sosreport See kernel messages dmesg See current boot parameters cat /proc/cmdline Get CPU information cat /proc/cpuinfo Memory profile cat /proc/meminfo Magic SysRq Wiki Page Installs & Updates (Ubuntu) most apt-get or apt-cache commands can also be ran with just apt in 16.04 Check for available updates apt-get clean apt-get update apt-get -s upgrade Install available updates apt-get clean apt-get update apt-get upgrade To upgrade from major release to major release 1. apt-get install update-manager-core 2. sudo do-release-upgrade Refresh available packages apt-get update Search for packages apt-cache search [name] Get package info apt-cache show [name] Get package info (get version before install) apt show [name] Install a package from repo apt-get install [name] Install from package dpkg --install /path/to Remove a package apt-get remove [name] Remove a package and configuration apt-get purge [name] Check for package upgrades apt-get -s upgrade Upgrade packages apt-get upgrade Detailed list of all installed packages dpkg --list Create a backup list of all installed software dpkg --get-selections > /path/to/output.pkgs.txt Info about installed package dpkg --status [name] List files in installed pkg dpkg --listfiles [name] List config files in install pkg dpkg-query --show -f '${Conffile}\n' [name] Get info about package file dpkg --info [name] List files in a package file dpkg --contents [name] Show package dependencies apt-cache depends Show reverse dependency apt-cache rdepends Find package that installed file dpkg --search filename Find package that provides file apt-file search filename Verify all installed packages debsums Clear local cache apt-get clean Clear only obsolete from cache apt-get autoclean Upgrade system apt-get dist-upgrade Repo configuration /etc/apt/sources.list Additional repos /etc/apt/source.list.d Edit sources list apt edit-sources Installation & Updates (RHEL) anaconda-kgs.conf should list all installation options What kinds of updates are available yum update Install just security updates yum update --[section] Install local package without key yum localinstall --nogpgcheck Push along an install yum --skip-broken Install latest kernel yum install kernel Search for package that’s installed on system yum search installed Which packages provide a particular file yum provides [file] Add EPEL repo yum install epel-release yum repolist Find which package installed a file rpm -qf [file] What scripts were run by an installer rpm -q [file] --scripts or --triggerscripts Find application config files rpm -qc [exec] Determine which package owns conf file rpm -qcf [conf file] Information about a particular package rpm -qpi [package] Information about a particular app/package repoquery -il [name] Determine what get’s installed & where rpm -qlp [package] View scripts included in package rpm -qp --scripts [package] Display list of all recently installed packages rpm -qa --last Extract files from package rpm2cpio [package.rpm] | cpio -id Create repo files Must include ID & base (man yum.conf) & place in /etc/yum.repos.d Upgrade from 6.x to 6x+1 version in RHEL 6: yum clean all yum --releasever=6.x update Upgrade from 5.x to 5.x+1 in RHEL 5: rpm -Uvh ftp:///path/to/repo.noarch.rpm rpm -Uvh ftp:///path/to/repo.rpm or @x86_64.rpm yum clean all yum update yum yum update Configure the Applications menu alacarte Downgrade a package with yum Config files changed during initial install are _not_ reverted back as part of downgrade yum history list yum history undo [number of item to remove] Monitoring & Logging See also Notable Utilities See logs from this boot session journalctl -b See logs since a particular date journalctl --since="####-##-## ##:##:##" (year-month-day 24:00:00 time) See logs since a relative time journalctl --since="[relative time]", e.g. --since="20 min ago" Export top values to output file top -b -n 1 > /path/to/output Get disk statistics over time sar -b Network ip & ss are the modern equivalents of arp, ifconfig and netstat arp -a == ip n ifconfig == ip a ifconfig [interface] == ip a show dev [interface] ifconfig [interface] up == ip link set [interface] up ifconfig [interface] down == ip link set dev [interface] down netstat -r or route == ip r netstat -a == ss -a List network interfaces on Centos/RHEL 7 ip a nmcli -p dev Get UUID for network interface on Centos/RHEL 7 uuidgen [interface] Configure static IP on Centos/RHEL 7 Edit or create /etc/sysconfig/network-scripts/ifcfg-[interface ID] Include network configuration information, including UUID systemctl restart network Configure static IP on Ubuntu Edit /etc/network/interfaces Include the following: auto [interface] iface [interface] inet static address x.x.x.x netmask x.x.x.x network x.x.x.x broadcast x.x.x.x gateway x.x.x.x dns-nameservers x.x.x.x y.y.y.y. 14.04 and lower: sudo /etc/init.d/networking restart 16.04: sudo systemctl restart networking Bring an interface up or down ifup [int] or ifdown [int] Current firewall rules (iptables) iptables -L Current firewall status (ufw) ufw status verbose Wireless network configuration iwconfig Wireless networking status information iwlist Security SELinux status sestatus See current SELinux value getenforce Change SELinux value setenable Listing of SELinux policy path-to-context mappings semanage fcontext -l Set SELinux to Permissive seenforce Permissive See security context of files ls -Z Map SELinuxsecurity context to current directory/place restorecon -R Temporary change SELinux security context chcon Boot into single user Boot into grub, select kernel and then add “1” or “single” to kernel parameters Services For Ubuntu 16.04+ / RHEL 7+ with systemd systemd service files to control applications are in /etc/systemd/system/. Unit files found in this directory location take precedence over any of the other locations on the filesystem View how long each startup process took systemd-analyze blame List all active services (aka service units) systemctl list-units List all services (aka service units) even if not active systemctl list-units --all Get service or application state systemctl status [application or service.service] systemctl is-active [application or service.service] systemctl is-enabled [application or service.service] systemctl is-failed [application or service.service] Manipulating services or applications systemctl start/stop/restart/reload [application or service] Start a service or application on boot systemctl enable [application or service.service] Remove a service or application from boot systemctl disable [application or service.service] Update systemd after changing service config or unit file systemctl daemon-reload Tree list of service dependencies systemctl list-dependencies Users & Groups Add a user useradd username Set user password passwd username Add a group groupadd groupname Change user to group user -aG groupname username User password settings chage -l username Get information about user getent passwd user Create a new sudo user on Centos/RHEL adduser [username] passwd username usermod -aG wheel [username] (wheel membership == sudo privileges) Create a new sudo user on Ubuntu adduser [username] usermod -aG sudo [username] Notable Utilities atop and htop: top improvements bonnie++: disk testing and performance utility dstat: combined vmstat and iostat glances: curses/python-based monitoring tool iftop: displays bandwidth usage information on an network interface mrt: network diagnostic tool nload: visualize network traffic nmon: performance utility swat: Samba Server config tool (yum install swat; chkconfig swat on; service xinetd restart; 127.0.0.1:901) Non-systemd/Older OSes Scripts in /etc/init.d and /etc/rc.* sys init vs systemd commands _Services_ service [application or service] start == systemctl start [application or service] or [application or service].service service [application or service] stop == systemctl stop [application or service] or [application or service].service service [application or service] restart == systemctl restart [application or service] or [application or service].service service [application or service] reload == systemctl reload [application or service] or [application or service].service service [application or service] status == systemctl status [application or service] or [application or service].service chkconfig [application or service] on == systemctl enable [application or service] or [application or service].service chkconfig [application or service] off == systemctl disable [application or service] or [application or service].service _Runlevels_ 0 == runlevel0.target, poweroff.target 1, s, single == runlevel1.target, rescue.target 2, 4 == runlevel2.target, runlevel4.target, multi-user.target 3 == runlevel3.target, multi-user.target Multi-user, non-graphical. 5 == runlevel5.target, graphical.target Multi-user, graphical. 6 == runlevel6.target, reboot.target Enable persistent service service [name] start, chkconfig [name] on, chkconfig --list [name] Current startup information for a service (sys init) chkconfig --list [service] List installed services (sys init) cat /etc/init.d Enable persistent service Alt initctl restart|stop|start|reload|status [service] Change runlevels tellinit [runlevel] What starts at boot (Ubuntu) sysv-rc-conf Add a new service (non-systemd) update-rc.d [service name] defaults Remove a service (non-systemd) update-rc.d -f [service name] remove Manually set RunLevel for a service (non-systemd) update-rc.d [service] start [priority number] [RunLevel number. If listing multiple, use single space] e.g. update-rc.d apache2 start 10 2 3 4 5