Archive for the ‘linux’ Category

Ssh tunnel

Random port tunnelling using a private key: #!/bin/sh   ssh -L 5446:hostname:5446 -i /home/imran/Servers/iaghayev iaghayev@192.168.1.10 -p 2222 Mysql port tunnelling using a private key: #!/bin/sh   ssh -L 3309:127.0.0.1:3306 -i /home/imran/Servers/iaghayev iaghayev@192.168.1.10 -p 2222

Smart live server updates through links

Use /var/www-production & /var/www-prerelease Link /var/www.repo1 to /var/www-production and /var/www.repo2 to /var/www-prerelease. Update /var/www-prerelease, test, do customizations. When ready simply swap the links, move prerelease production and production to prerelease

Ubuntu reset root password

If you forgot root’s password follow these steps to reset it: 1. Reboot, press ESC to get to GRUB boot loader menu 2. Choose from the list kernel with (recovery mode) 3. From the menu screen choose "Drop to root shell prompt" 4. By default it gives you read-only filesystem Run this for read/write: mount […]

Ssh key generation and folder files explain

Ssh protocol version 1 key generation. ssh-keygen When asked for a “passphrase”, we won’t enter one. Just press enter twice. It will generate 2 files: /home/user/.ssh/id_rsa.pub /home/user/.ssh/id_rsa 2. Copy id_rsa.pub to the remove host scp id_rsa.pub user@hostname:/home/user/.ssh/id_rsa.pub or ssh-copy-id -i .ssh/id_rsa.pub user@hostname 3. Login to remote host and add to authorized_keys file ssh hostname -v […]

Find programs that listens on network ports/sockets

sudo netstat -peanut

Linux adding a new user

useradd -d /home/testuser -m testuser

Linux how-to delete the first line in text file

tail -n +1 filename.txt > filename.txt.new

Generate pdf from jpg files

Use convert utility from ImageMagick package /usr/bin/convert *.jpg result.pdf

Image optimize

Run optipng to optimize png files in directory: for i in `ls`; do optipng -i0 -o7 -zm1-9 $i; done Run optipng for a single file: /usr/bin/optipng -i0 -o7 -zm1-9 upload/banner/kaspi132px.png Run jpegoptim for a single file: /usr/bin/jpegoptim –strip-all upload/banner/kaspi132px.jpg Run gifscle for a single file: /usr/bin/gifsicle -b -O2 upload/banner/kaspi132px.gif

Running cron job every 5 minutes

1. Go to editor: crontab -e 2. */5 * * * * /usr/bin/curl https://www.natality-dating.com/1/bulkmailer/1 2>/dev/null >/dev/null 3. Check the result: crontab -l 4. Check if cron is running: ps -aef | grep cron