Unix Tools

🤗 User Management

# Change username
usermod -l new old

📁 File Management

tar -xzvf (uncompress gz)
tar -xjvf (uncompress bz2)

tar -czvf router.apkovl.tar.gz router/ (compress to gz)

When filesystem is mounted under SMB, even root will have trouble settings correct permissions through the sudo command. You can get around this problem by specifying --no-same-owner

tar xzvf stuff.tar.gz --no-same-owner -C /media/dest

💾 Disk Management

df -h # human readable disk usage

💻 Hardware Management

lsmod # list loaded kernel modules

# blacklisting kernel modules
vim /etc/modprobe.d/blacklist.conf

# see installed firmware
cd /lib/firmware/*

🌐 LAN Management

# All saved / bootable interfaces
cat /etc/network/interfaces

# Example

auto lo iface lo inet loopback

iface eth0 inet manual

auto-hotplug wlan0 iface wlan0 inet dhcp wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

# All current available interfaces
ls /sys/class/net

# Probe master mode for interface
iwconfig wlan1 mode master

TIL wtf a subnet mask actually is

Only change within the range of numbers not AND'ed by that value

ip = #CIDR Notation

base =

subnet-mask =

 AND 11111111.11111111.11111111.00000000
Configuring A DHCP Service
sudo apt install isc-dhcp-server
# or
sudo apk add dhcp-server-vanilla dhcp-openrc 



🌎 WAN Management

SSH Reverse Tunneling
ssh –f –N –T –R 2222:localhost:22 [email protected]
  • -f: tells the SSH to background itself after it authenticates, saving you time by not having to run something on the remote server for the tunnel to remain alive.
  • -N: if all you need is to create a tunnel without running any remote commands then include this option to save resources.
  • -T: useful to disable pseudo-tty allocation, which is fitting if you are not trying to create an interactive shell.
    autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3"
  • autossh for auto reconnect on intervals 
    autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" –f –N –T –R 2222:localhost:22 [email protected]

🔑 Auth / Logging

> user      pts/4  Sun Jan 26 04:05   still 
> logged in

vim /var/log/auth.log
> Jan 24 03:07:47 hostname sshd[14435]: Invalid user admin from port 42579

cat /etc/passwd # for user lists and shell defaults

🌱 Init Systems

Open RC


rc-update add <service> <runlevel>
rc-update del <service> <runlevel>
rc-service <service> <start stop restart>
rc <runlevel> 

Script Example

  • init scripts in /etc/init.d
  • update-rc.d does not work fine if there is no specific comment block in the start script that looks like this:
  • On Raspbian Buster (v10) #! /bin/sh must appear right before the BEGIN INIT INFO block.


Provides: reverse-ssh



Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: Start reverse ssh at boot time

Description: Start reverse ssh at boot time.


. /etc/init.d/functions.sh

depend(){ need sshd }

start() { echo "Opening reverse shell." /usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -f -N -R 8000:localhost:22 [email protected] }

### Systemd

#### Commands

sudo service

start</p> <pre><code> #### Script example</code></pre><p>#!/bin/sh  #ssh -R 8000:localhost:22 <a href="mailto:vpn@">vpn@</a> </p> <h3 id="begin-init-info-1">BEGIN INIT INFO</h3> <h1 id="provides-new-reverse-ssh">Provides: new-reverse-ssh</h1> <h1 id="required-start-1">Required-Start:</h1> <h1 id="required-stop-1">Required-Stop:</h1> <h1 id="default-start-2-3-4-5-1">Default-Start: 2 3 4 5</h1> <h1 id="default-stop-0-1-6-1">Default-Stop: 0 1 6</h1> <h1 id="short-description-start-reverse-ssh-at-boot-time-1">Short-Description: Start reverse ssh at boot time</h1> <h1 id="description-start-reverse-ssh-at-boot-time-1">Description: Start reverse ssh at boot time.</h1> <h3 id="end-init-info-1">END INIT INFO</h3> <p> start() { echo "Opening reverse shell." /usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -f -N -R 8000:localhost:22 <a href="mailto:vpn@">vpn@</a> }  case "$1" in start) start;; *) echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2 exit 1;; esac </p> <p>```</p> <h5 id="references">References</h5> <ul> <li><a href="https://www.linux.com/tutorials/managing-linux-daemons-init-scripts/">https://www.linux.com/tutorials/managing-linux-daemons-init-scripts/</a></li> <li><a href="https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/">https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/</a></li> <li><a href="https://askubuntu.com/questions/936728/how-to-keep-ssh-connection-alive">https://askubuntu.com/questions/936728/how-to-keep-ssh-connection-alive</a></li> <li><a href="https://unix.stackexchange.com/questions/102918/service-to-start-on-boot-doesnt-work-with-update-rc-d-command">https://unix.stackexchange.com/questions/102918/service-to-start-on-boot-doesnt-work-with-update-rc-d-command</a></li> </ul>