Tuesday, January 9, 2018

Rsync to a different ssh port

In order to use rsync with different ssh post, you can use -e flag, and supply ssh command with port option. For example, I want to transfer a file called /root/book.txt from a server called project.local with sshd running on port 55522 to local partition /mnt, I can use this command:

$ rsync -avz --progress -e "ssh -p 55522" root@project.local:/root/book.txt /mnt

where:
-a for archive mode
-v for verbose
-z to compress data during transfer
--progress for showing progress of the copy
-e to specify the remote shell to use, in this case to use ssh to port 55522

Wednesday, January 3, 2018

Resizing partition in centos after vmware hardisk extension

This is usually done, when the hardisk space for the CentOS VM is running low.


Check your current disk size
# fdisk -lu /dev/sda

To increase the size of the hardisk image, shutdown the centos VM
# poweroff

Increase the hardisk image in VMware

Power on the centos VM














Once logged in, check back whether you have increased your disk size
# fdisk -lu /dev/sda











Create new partition on the new disk space
# fdisk /dev/sda
Press:
n   {new partition}
p   {primary partition}
3   {partition number}
t    {change partition id}
8e {Linux LVM partition}
w  {write partition change to disk}

Reboot the vm
# reboot

Check the new partition
# fdisk -lu /dev/sda










Create physical volume (PV) on the new partition
# pvcreate /dev/sda3

Check list of PV
# pvs






Extend the current Volume Group (VG) to include the new PV, and check the new VG size
# vgextend centos /dev/sda3
# vgs







Extend the current Logical Volume (LV), and check the new size of logical volume 
# lvextend /dev/mapper/centos-root /dev/sda3
# lvs







Resize / partition
# resize2fs /dev/mapper/centos-root





Check the new size
# df -h /
before resize:




after resize:







Sunday, December 24, 2017

Start a simple http server using python3

This is very simple, because python3 already has a built in module for http server, called http.server. To use this module, run:

$ python3 -m http.server 8000

whereby 8000 is the port you want the http server to run on. To use privileged ports (under 1024) , just append sudo to the above command, like below:

$ sudo python3 -m http.server 80

Once the command run, you can access the current directory via web, like below:



Once done, press Ctrl-c to terminate the server.

Tuesday, September 26, 2017

Generating ssh key (public and private)

  1. Open terminal
  2. Run ssh-keygen command
  3. When prompted for filename to save, press enter for default location
  4. When prompted for passphrase, you can either put in a passphrase (highly recommended), or just leave it empty (not recommended)
  5. Your public key is /home/username/.ssh/id_rsa.pub, and your private key is /home/username/.ssh/id_rsa 

Wednesday, September 13, 2017

Using yum via socks proxy using proxychains

This is useful when you have a CentOS/Redhat server that needs to be updated, but does not have internet connection to get app from the repo. The only requirement is that the server need to be able to ssh into another server that have internet connection. Let's begin.

Download source for proxychain. You can use the server that have internet connection to do this
# wget -c https://github.com/rofl0r/proxychains-ng/archive/master.zip

Transfer the downloaded file into the server without internet, and unzip the file into /usr/local/src
# unzip master.zip -d /usr/local/src

Change directory to /usr/local/src/proxychains-ng-master
# cd /usr/local/src/proxychains-ng-master

Compile, configure and make
# ./configure && make && make install && make install-config

Setup a dynamic socks proxy on port 8888 by ssh'ing into the server that has internet connection:
# ssh foo@server.with.internet -D 8888

Set proxychains to use the dynamic tunnel, by changing the last line of /usr/local/etc/proxychains.conf to "socks4 127.0.0.1 8888"
# tail -1 /usr/local/etc/proxychains.conf 
socks4  127.0.0.1 8888


Open a new terminal, and run yum command with proxychains. You can see that your yum is tunneled via localhost port 8888:
# proxychains4 yum update
[proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.12
...