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
fdisk
parted
π» 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 = 192.168.5.255/24 #CIDR Notation
base = 192.168.5.255
subnet-mask = 255.255.255.000
11000000.10101000.00000111.01111111
AND 11111111.11111111.11111111.00000000
βββββββββββββββββββββββββββββββββββ
1100000.00001010.00000111.00000000
Configuring A DHCP Service
sudo apt install isc-dhcp-server
# or
sudo apk add dhcp-server-vanilla dhcp-openrc
Modify Interfaces
Modify dhcpd.conf https://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/
https://wiki.alpinelinux.org/wiki/Small_Office_Services#Install_and_Configure_DHCP_and_DNS_services
https://wiki.debian.org/NetworkConfiguration#Manual_config
π 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
last
> user pts/4 108.210.178.151 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 141.98.81.37 port 42579
...
cat /etc/passwd # for user lists and shell defaults
π± Init Systems
Open RC
- They are finally writing this π - https://wiki.alpinelinux.org/wiki/Writing_Init_Scripts
- https://wiki.gentoo.org/wiki/OpenRC
- https://wiki.alpinelinux.org/wiki/Alpine_Linux_Init_System
Commands
rc-update add <service> <runlevel>
rc-update del <service> <runlevel>
rc-service <service> <start stop restart>
rc-status
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.
#!/sbin/openrc-run
BEGIN INIT INFO
Provides: reverse-ssh
Required-Start:
Required-Stop:
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.
END INIT INFO
. /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 vpn@192.168.0.0 }
### Systemd
#### Commands
sudo service
#### Script example
#!/bin/sh ο»Ώ #ssh -R 8000:localhost:22 vpn@167.172.148.6 ο»Ώ
BEGIN INIT INFO
Provides: new-reverse-ssh
Required-Start:
Required-Stop:
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.
END INIT INFO
ο»Ώ start() { echo "Opening reverse shell." /usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -f -N -R 8000:localhost:22 vpn@167.172.148.6 } ο»Ώ case "$1" in start) start;; *) echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2 exit 1;; esac ο»Ώ
```
References
- https://www.linux.com/tutorials/managing-linux-daemons-init-scripts/
- https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/
- https://askubuntu.com/questions/936728/how-to-keep-ssh-connection-alive
- https://unix.stackexchange.com/questions/102918/service-to-start-on-boot-doesnt-work-with-update-rc-d-command