System administration

Important commands, user accounts.

Command

Description

id

Show current uid, gid and additional groups.

whoami

Display current user name only.

cat /etc/passwd

Show all user accounts.

cat /etc/group

Show all groups.

pw useradd <user> -m

Create user; -m= create home directory.

passwd

passwd <user>

Set or change password for yourself or another account (administrator only).

pw usermod <user> -G wheel

Add users to the group "wheel" or simply edit /etc/group directly.

pw userdel <user> -r

Delete user; -r= remove home directory and all content.

cat /etc/master.passwd

View all accounts, including encrypted passwords.

vipw

Lock master.passwd
Edit it and rebuild password databases.

Important commands, file system.

Command

Description

mount

Display mounted file systems.

df

df -h

Shows occupied and free space in all mounted file systems. Adding -h = shows 1G instead of 1048576.

du -c <path>

Adds space occupied by files or directories in the specified path or in the current directory.

mount -r -t cd9660 /dev/ acd0 /cdrom

Mount device /dev/acd0 [IDE CD] in directory /cdrom; file system type is cd9660;-r=read-only.

umount /cdrom

Eject the device. The device must not be used.

fstat

List processes with open files.

cat /etc/fstab

Display file system table.

mount /cdrom

Mount /cdrom with parameters from /etc/fstab

mount -a

Mount all file systems in /etc/fstab except those marked "noauto" (this happens during normal booting, but is useful when booting in single-user mode).

Important commands, packages.

Command

Description

pkg info

Display an overview list of the installed packages.

pkg info <package>

Display a detailed description of the package.

pkg info -l <package>\*

Display a list of all files contained in the package.

pkg add <file>-1.2.3.tbz

Install package from file.

pkg add -r <package>

Install package from the default FTP server.

PACKAGEROOT="ftp://ftp.uk.freebsd. org" pkg add -r <package>

Install package from an alternative FTP server.

pkg install <package>

Installs package from remote repository or local archive.

pkg delete <package>

Uninstalling a package.

Important commands, kernel modules.

Command

Description

kldstat

Display loaded modules.

kldload <module>

Load the named module and all modules on which it depends.

kldunload <module>

Unload module.

Important commands, network.

Command

Description

ifconfig

Display all interfaces.

ifconfig igb0 192.168.0.1/24

Configure interface.

netstat -r -n

Display table with redirects.

route add default 192.168.0.254

Add a static default route.

ping <IP-Adress>

Send test packages. Terminate with ^C.

traceroute -n <IP-Adress>

Send test packets and display intermediate routers.

tcpdump -i igb0 -n -s1500 -X

tcpdump -i igb0 -n tcp port 80 -w <file>

Displays complete packets that were sent and received via a specific interface. The second form shows only package headers to/from TCP port 80.

Use the option -w <file> to save the network dump in file <file>.

/etc/rc.d/netif start

Initialize network interfaces using the settings in /etc/rc.conf.

/etc/rc.d/routing start

Initialize static routes from the settings in /etc/rc.conf.

/etc/rc.d/dhclient start

Configure interfaces marked with "DHCP" in /etc/rc.conf.

netstat -finet -n

Display active network connections. Use -a to add listening sockets.

sockstat -4 -l

Displays processes that listen to IPv4 and IPv6 sockets.

Important commands, processes.

Command

Description

ps aux

Show all processes.

ps aux | grep <processname>

Show all processes that correspond to the pattern <processname>. Note that grep <processname> can be displayed itself.

top

Continuous display of the most active processes. Quit with q.

kill <pid>

The process with the specified process ID is quickly cleaned up and terminated.

Important commands, system status.

Command

Description

Alt-F1 ... Alt-F8

Switch between virtual consoles.

date

Display current date and time.

ntpdate -b <server1> <server1> ...

Synchronize the clock with the specified NTP servers.

uptime

Display time since last restart and average load.

w

Shows who is currently logged in.

last -10

Display the last 10 logins.

Shutdown -r now

Restart.

doas shutdown -p now

Switch-off.