log

taiar

Linux Cli Snippets

Just some Linux Cli / Bash snippets i’d like to remember.


Turn monitor off (until mouse move of keyboard press)

1
$ xset dpms force off

SSH auto-login

Create SSH directory on user folder (if doesn’t exists yet):

1
2
a@A:~> ssh b@B mkdir -p .ssh
b@B's password:

Append a’s new public key to b@B:.ssh/authorized_keys and enter b’s password one last time:

1
2
a@A:~> cat ~/.ssh/id_rsa.pub | ssh b@B 'cat >> ~/.ssh/authorized_keys'
b@B's password:

From now on you can log into B as b from A as a without password:

1
a@A:~> ssh b@B

Depending on your version of SSH you might also have to do the following changes:

  1. Put the public key in .ssh/authorized_keys2
  2. Change the permissions of .ssh to 700
  3. Change the permissions of .ssh/authorized_keys2 to 640

Taken from here http://www.linuxproblem.org/art_9.html


Formatting USB Pen Drive

Find out the device:

1
$ mount

Umount the device:

1
$ umount /dev/sdb1

Format the device:

1
$ mkfs.vfat /dev/sdb1

Burning ISO to USB drive

1
dd bs=4M if=path-to-your.iso of=/dev/sdb

Sync folders

1
rsync -azrP /**/**/**/dir user@addr:/**/parentfolder

Will sync local dir folder inside parentfolder in a remote location.


Fix NTFS issues in partitions

1
sudo ntfsfix /dev/sdb1

Find PID that is running in some port

1
lsof -t -i:27017

Find what process is listening which port

1
sudo lsof -i -P -n | grep LISTEN

That’s it for now! :)