# Linux notes


## Accesso con chiave pubblica su server remoto

	ssh-keygen -t rsa -b 4096
	ssh-copy-id utente@indirizzo_server

## Create a branch

	git init; git add .; git commit -m "Vanilla version"; git branch acme; git checkout acme

## Apply a patch

	patch -p1 < linux-4.4.79.patch

## Creare una patch

	git diff altro_branch > nomefile.patch

## Show the Debian version

	lsb_release -a

## Add User to the Sudo Group

	usermod -aG sudo username

## Search a pattern inside a path

	grep -rnw '/path/to/somewhere/' -e 'pattern'

## Create a ramfs

	sudo mkdir /mnt/ramdisk
	sudo mount -t ramfs -o size=1.5g tmpfs /mnt/ramdisk
	sudo chmod 777 /mnt/ramdisk

## Launch remote comands via SSH

	ssh tanzilli@acmesystems.it "ls /var/www/new-acme-website"

* <http://xmodulo.com/2013/04/how-to-mount-remote-directory-over-ssh-on-linux.html>

## Mount a remote folder via SSH

	sudo apt-get install sshfs
	sudo usermod -a -G fuse [user_name]
	exec su -l $USER
	sshfs my_user@remote_host:/path/to/directory [local_mount_point]
 
## Create a file pattern

	dd if=/dev/urandom of=pattern bs=1 count=256M


## Compare two binary files

	xxd file1.bin > file1.hex
	xxd file2.bin > file2.hex
	diff file1.hex file2.hex

## rsync

	rsync -avc foxg20-modules/lib/. root@192.168.1.90:/lib/.


## Disable a Linux account

	sudo passwd -l username

Re-enable::

	sudo passwd -u username

## Monitorare gli interrupt in arrivo

	watch --n 1 -d cat /proc/interrupts

## Create una tmpfs
	
	/etc/fstab tmpfs /tmp tmpfs defaults 0 0

## Disk swap

	sudo fallocate -l 1G /swapfile
	sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
	sudo chmod 600 /swapfile
	sudo mkswap /swapfile
	sudo swapon /swapfile

To make the change permanent open the /etc/fstab file:

	sudo nano /etc/fstab

and paste the following line:

	/swapfile swap swap defaults 0 0

## Swap on usb dongle

	mkswap /dev/sda1 && swapon /dev/sda1

### Links

* <https://linuxize.com/post/how-to-add-swap-space-on-debian-10/>

## Video grabbing

	sudo ffmpeg -f x11grab -s 1920x1080 -r 25 -i :0.0 -sameq /tmp/out1.mpg

## Show the system messages

	sudo journalctl -k

## Enable a user as sudoers (Debian)

	usermod -aG sudo username

## Accedere ad un server SSH con la chiave pubblica

* <https://linuxize.com/post/how-to-setup-passwordless-ssh-login/>
