Linux cmd memo - Jiajun-Liu/Snippets GitHub Wiki

Setup linux startup program

sudo mv /filename /etc/init.d/

sudo chmod +x /etc/init.d/filename

sudo update-rc.d filename defaults

  • Note the file should be placed under /etc/init.d/

or more easily:

Add cron job

crontab -e

And add your entry

  • -- all

*/1 -- every

Mounting .iso image

mount -o loop image_path mount_dest

Replace strings in files

perl -p -i -e 's/oldstring/newstring/g' file_name

Reverse ssh tunnelling

Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99)

1, SSH from the destination to the source (with public ip) using command below:

ssh -R 19999:localhost:22 [email protected]

/ssh -R [bind_address:]port:host:hostport dest_usr@dest_host/

  • port 19999 can be any unused port.

2, Now you can SSH from source to destination through SSH tuneling:

ssh localhost -p 19999

Add startup script in Linux

make sure target program - say sample.py - is set with correct permissions -best 777

put script, say, 'test.sh', into /etc/init.d, in which executes '/path/sample.py &'

update-rc.d test.sh defaults

IMPORTANT: make sure every file referenced in the start script is set with correct permissions IMPORTANT: add keep alive to the /etc/ssh/ssh_config, add

Host *

ServerAliveInterval 60