adduser # wrapper script to add userschsh # change user shell and other infopw groupadd teamtwo # add a group to the systempw groupmod teamtwo -m <username> # add a user to a group/etc/group # file to edit groups manuallyid # show group membership for current user
System Configuration
cat /var/run/dmesg.boot # show boot log with info about disks and pci deviceskenv # show bios, board and chassi info (dump from kernel env)pciconf -l -cv # show info about PCI devices of the machinecamcontrol devlist -v # list of attached ATA devicesifconfig # show and configure network interface parameterssysctl # tool to show/set all system/kernel coniguration variablessysctl -a # show all system/kernel configuration variablessysctl hw # show hardware related info and settingssysctl net # show all network related info and settingssysctl hw.model # show CPU modelsysctl net.inet.tcp.delayed_ack=0# disable delayed ack in tcp
System Statistics
top # display and update information about the top cpu processesps auxwww | grep <processname> # display process statusCTRL-t # on running commands will output useful infosystat -vmstat 1# show general overview of load, memory, interrupts, disk iosystat -iostat 1# show disk throughputsystat -ifstat 1# show network throughput for all interfacessystat -netstat 1# show netstat output but automatically refreshedsystat -tcp 1# show tcp statistics
ZFS
zfs list # list all zfs datasets (volumes)zfs list -t snapshot # list all zfs snapshotszfs list -r -t snapshot <pool> # list zfs snapshots for a given poolzfs snapshot <pool>/<dataset>@<name> # generic way of creating a snapshot of a dataset in a storage poolzfs snapshot -r tank@2014021301 # create a snapshot of all datasets in the pool "tank"zfs create <pool>/<dataset> # create a new datasetzfs rollback <pool>/<dataset>@name # rollback of a dataset to a given snapshotzfs destroy <pool>/<dataset> # destroy a dataset / remove it from the poolzfs destroy <pool>/<dataset>@name # destroy a snapshotzfs set <key>=<val> <pool>/<dataset> # generic way of setting options on a given datasetzfs setcompression=lz4 tank/var/log # enable LZ4 compression on /var/logszfs get compressratio <pool>/<dataset> # show the current compression ratio of a datasetzfs send -R tank@snapshot |\ # send all datasets@snapshot recursively to another hostssh root@[IP] zfs recv -F tank
zfs unmount <pool>/<dataset> # unmount a zfs datasetzfs upgrade -r <pool> # upgrade all volumes in the pool (technically its the root volume e.g. tank)zpool status # show health info about currently imported ZFS storage poolszpool scrub # check all written blocks for consistencyzpool iostat -v tank # show more information about the pool including log deviceszpool add <pool> mirror <dev1> <dev1> # add two disks as mirror to a storage poolzpool remove <pool> <device> # remove single devices or mirror sets from the storage poolzpool upgrade <pool> # upgrade the storage pool to latest version
Software
### Portsportsnap fetch # fetch the latest portfilesportsnap update # update the portfiles on disk with the previously fetched portfilesportsnap update -p /usr/jails/basejail/usr/ports # update ports tree for jailswhereis <portname> # show the directory of the portfilecd /usr/ports/*/<portname> # find the parent directory of a given portnamelocate <portname> | grep ports # manual way of searching for portscd <portdir> && make install # compile and install a portcd <portdir> && make config # re-run configuration of a port when availablecd <portdir> && sudo make deinstall clean reinstall # upgrade the port### Packagespkg search <packagename> # search for binary packagespkg install <packagename> # install binary package and its dependenciespkg delete <packagename> # delete an installed packagepkg autoremove # remove unneeded dependenciespkg info # show list of currently installed ports/packages with version infopkg version # show which ports/packages are outdated and need an updatepkg upgrade <packagename> # upgrade a packagespkg which <filename> # find out which package installed a given filepkg audit -F # look for ports/packages with security vulnerabilities## Systemfreebsd-update fetch # fetch updates from serverfreebsd-update -r <target> upgrade # fetch upgrades to specified version (e.g. '10.1-RELEASE') from serverfreebsd-update install # install downloaded updates/upgrades
Services
service -l # list all available servicesservice -e # list all enabled servicesservice <servicename> status # show the status of the service with the given servicenameservice <servicename> start # start the service with the given servicenameservice <servicename> stop # stop the service with the given servicenameservice <servicename> restart # restart the service with the given servicenameservice <servicename> reload # reload the configuration of the service with the given servicename
Network
ifconfig <iface> inet <ip/mask> # configure IP address on interfaceifconfig <iface> inet <ip/mask> alias# configure IP address alias on interfaceifconfig <iface> del <ip> # remove IP address from interfaceroute add -net default <gw_ip> # add default routeroute add -net <ip/mask> <gw_ip> # add a custom route for given network/etc/rc.d/netif restart &&\ # restart networking and routing after changing the configuration/etc/rc.d/routing restart without rebooting. Execute in tmux or screen session
netstat -rn # display routing tablenetstat -an # display all connectionsnetstat -m # display buffer usagenetstat -Lan # display status of listen queuesnetstat -s # display extensive statistics per protocol (use -p tcp to only show tcp)sockstat -l # display listening sockets, process names and pidssysctl kern.ipc.numopensockets # display number of open socketsvmstat -z | egrep "ITEM|tcpcb"# number of hash table buckets to handle incoming tcp connections increase net.inet.tcp.tcbhashsize if hitting the limit
sysctl net.inet.tcp.hostcache.list # display current content of hostcache with its parameters per IP
Firewall
pfctl -si # show current state table and counters (useful for tuning)pfctl -s state # show current content of state tablepfctl -d # disable the firewallpfctl -e # enable the firewall
IPsec
ipsec start # start VPN and establish (auto=start) VPN connectionssetkey -D # show extensive Kernel information about current connectionssetkey -DP # show more condensed connection informationipsec statusall [conn]# show returns detailed status information either on connection or all connections if no name is provided
ipsec leases # show current leases from virtual IP address poolipsec rereadsecrets # flushes and rereads all secrets defined in ipsec.secretsipsec rereadall # flushes and rereads all secrets defined in ipsec.secrets as well as all certificates and and certificate revocation lists
ipsec update # sends a HUP signal to the daemon that determines any changes in ipsec.conf and updates the configuration on the running IKE daemon charon
ipsec reload # sends a USR1 signal to the daemon that reloads the whole configuration on the running IKE daemon charon based on the actual ipsec.conf
ipsec restart # terminates all ipsec connections, sends a TERM signal to the daemon and restarts it afterwards
ipsec stroke up [conn]# initiate connection [conn]ipsec stroke down [conn]# terminate connection [conn]
ezjail
ezjail-admin start|stop # start and stop all the jailsezjail-admin start|stop <JID>|<hostname># start and stop individual jail
ezjail-admin list # list all the jails on the host systemezjail-admin console <JID>|<hostname> # open root shell into jailezjail-admin create -f exmaple <hostname> <IP> # create a new jailezjail-admin delete -w hostname # delete the jail (in case you use zfs also delete the volume)ezjail-admin update -U -s 11.1-RELEASE # update basejail from -s <RELEASE> to current host system
Common sysctl’s to set
hw.usb.no_shutdown_wait=1# don't wait for USB devices when shutting down (if your system hangs when rebooting)kern.maxfiles=204800# Increase file descriptor limits kern.maxfilesperproc=200000