Skip to content

Instantly share code, notes, and snippets.



Last active May 28, 2021
What would you like to do?
Documents good sysadmin solutions and oneliners to problems.

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 netmask   
cli># ifconfig tun5 netmask   

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

socat TCP-LISTEN:80,fork TCP:<address>: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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment