Skip to content

Instantly share code, notes, and snippets.

@huyanhvn
Last active September 3, 2018 15:37
Show Gist options
  • Save huyanhvn/40ccba5ecf7d0dd5b8da to your computer and use it in GitHub Desktop.
Save huyanhvn/40ccba5ecf7d0dd5b8da to your computer and use it in GitHub Desktop.
Linux tricks
### Kill process and all its children
kill -- -$(ps -o pgid= $PID | grep -o '[0-9]*') (signal TERM)
kill -9 -$(ps -o pgid= $PID | grep -o '[0-9]*') (signal KILL)
### FIND TOP MEMORY USERS
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10
### SSH menu
~C
### SSH PORT FORWARDING
ssh TARGET -L127.0.0.1:1234:127.0.0.1:2345
your localhost port 1234 is mapped to TARGET:2345
ssh TARGET -R127.0.0.1:1234:127.0.0.1:2345
for reverse
ssh user@jumphost -L127.0.0.1:19990:TARGET:22
same port forwarding above, but through a jumphost if you don't have direct access to TARGET
### FIND PROCESSES RUNNING MORE THAN 4 DAYS
ps -eo pid,etime,args | awk 'substr($2,1,index($2,"-")-1)>4
### FIND FILES NOT OWNED BY USER
find . \! -user foo -print
### IPTABLES DROP ALL OUTBOUND CONNS USING SOURCE & DEST PORTS
Allow binding to source port range: sudo iptables -I OUTPUT -p tcp --dport <dest_port> -m multiport --sports <range e.g.: 1:1023> -j ACCEPT
Block binding to all ports: sudo iptables -A OUTPUT -p tcp --dport <dest_port> -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment