Scp files between two servers without the need to first copy the file locally.
scp -3 'username@server1:/home/user/filename.tar.gz' username@server2:/home/user/
Create point to point tunnel between two servers over ssh with a tun interface to avoid the need to open a firewall.
cli># ssh -w5:5 root@hserver
srv># ifconfig tun5 10.0.1.1 netmask 255.255.255.252
cli># ifconfig tun5 10.0.1.2 netmask 255.255.255.252
Oneliner to list block percentage on a filesystem
dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }'
Set block percentage
tune2fs -m1 /dev/sda1
Write line number and function name when debug bash script.
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
$ bash -x ./script
Run command as a service
$ socat TCP-LISTEN:6666,fork,reuseaddr exec:/command
Forward port to a different port.
socat TCP-LISTEN:9999,reuseaddr,fork,su=nobody TCP:nighter.se:80
socat TCP-LISTEN:80,fork TCP:<address>:80
TLS termination and MITM proxy
openssl req -new -x509 -keyout test.key -out test.crt -node
cat test.key test.crt > cert.pem
socat -v openssl-listen:443,reuseaddr,cert=./cert.pem,verify=0,fork tcp4:xx.xx.xx.xx:80
Log everything from terminal to file
exec >> /var/log/logfile 2>&1
Clone driver over ssh and create virtualbox image.
ssh root@host "dd if=/dev/sda | gzip -1 -" | dd of=image.gz status=progress
gunzip image.gz
VBoxManage convertfromraw image.bin image.vdi --format VDI
Fix gpg when switch yubikey
gpgconf --kill gpg-agent
gpg --card-status
Jq magic
{
"Items": {
"password": {
"S": "password"
},
"username": {
"S": "username"
}
}
Example JQ parsing
<command_output_json> | jq -r '.Items[] | "\(.username[]):\(.password[])"'
sudo sshfs -o allow_other,default_permissions username@server:/home/username/debug /mnt/debug
patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 ~/bin/hetty
pavucontrol