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

Listens for TCP packets for a given host in a giver network interface (local in this case)

1
sudo tcpdump -vvv -A host mycoolhost.dev.pt -s 0 -i lo

Remap Ctrl and Alt keys on the keyboard

Create a file called ~/.Xmodmap with the contents:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
! -*- coding: utf-8 -*-
! 2013-02-04

! swap Ctrl and Alt keys

! here's the default setting on special keys
!  xmodmap -pke | grep -P '(Control|Super|Alt|Menu)'

! keycode  37 = Control_L NoSymbol Control_L
! keycode  64 = Alt_L Meta_L Alt_L Meta_L
! keycode 105 = Control_R NoSymbol Control_R
! keycode 108 = Alt_R Meta_R Alt_R Meta_R
! keycode 133 = Super_L NoSymbol Super_L
! keycode 134 = Super_R NoSymbol Super_R
! keycode 135 = Menu NoSymbol Menu
! keycode 147 = XF86MenuKB NoSymbol XF86MenuKB
! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
! keycode 206 = NoSymbol Super_L NoSymbol Super_L

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 105 = Alt_R Meta_R
keycode 64 = Control_L
keycode 108 = Control_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L

After that, run:

1
xmodmap ~/.Xmodmap

Convert images to PDF (with imagemagick)

1
convert *.jpg pictures.pdf

Generate image with defined dimensions and color

1
convert -size 1x1 canvas:white white.gif

That’s it for now! :)