Category Archives: Linux

How to extend HDD space in ubuntu 20 VM (this example is hosted on ESXi)

After extending the hard disk of the VM in ESXi or any other hypervisor, reboot the VM and boot using a bootable GPARTED iso image.

Before the extention, this VM has 200GB HDD which is almost full now

Once the GPARTED gui comes up, confirm that the free space is showing up and then select the partition which needs to be extended and use the slider to extend it my moving it towards right side. Then click on SAVE to write the changes. We are done here so we can now reboot the machine to claim the newly added space in the OS. If the disk is 100% used then the OS will not let you make/save any partition chanes to the disk which is counter intutive but that is how it is designed so when the OS is rebooted, press escape button on keyboard and then select advanced ubuntu startup options and drop to root shell. Once here, run apt-get clear && apt-get autoremove this will remove enough space to enable you to write changes to the disk.

GPARTED – extending the partition
Reboot GPARTED

After the reboot, run these commands in this sequence to extend the volume.

######## ANOTHER METHOD #########

  • sudo parted
  • print free space (This will show the partitions with numbers and the free space, we will use the partition number and free space next)
  • resizepart <NUMBER> <FREE SPACE i.e. 90GB>
  • write
  • quit
  • sudo lsblk (Note down the name of the partition and volume)
  • sudo pvresize /dev/sda3 (it was /dev/sda3 in this case as shown in output of lsblk, make sure it is correct)
  • sudo lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
  • sudo resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
    • df -h (to check the resizing)

How utilize SSH tunnel for any remote service

This is something Advanced level so if you are a beginner, try to follow along and I will try to explain it in the easiest to understand way.

Why do we need SSH tunneling? Well, for me it makes it quite easy to manage the services from my private network to be available from the internet. All I need to do on my firewall is open or forward an open port to the SSH listening port on my SSH server. If you want to setup your SSH server, you may want to take a look at my other post.

In this post I will try to explain how to use RDP over SSH Tunnel. The idea is to access the RDP service on a Windows host from another computer without connecting to the RDP service port (by default 3389) using a SSH tunnel provided by an SSH server.

 

I am using PUTTY here.

  1. On the Client, open putty and scroll down on the left side and click on the + sign next to SSH to select Tunnels. Enter a port number higher than 1024 here which should not be same as any other running service on your (client) computer. I chose 2222 here and then enter the ip address of the host computer where you want to connect through tunnel (10.0.0.100 port 3389 providing RDP in our example) then click ADD.

     

     

  2. Now it should appear in the box above so scroll up on the left and click on Session.

     

     

  3. Now enter the ip address of the SSH server (10.0.0.2 and port 22 in our example) and click on OPEN.

     

     

  4. In the terminal window which just opened, enter the username and password for the SSH Server and keep it open.
  5. Now open mstsc.exe on your computer and use the localhost as the ip and 2222 (the one we chose in step 1) as the port and click on connect. You should see the login window and that’s it.

     

    Just remember to keep the Putty window open else the tunnel will drop and you will have to re-establish the connection. Have fun.

     

     

     

How to setup a lightweight Linux (Ubuntu) based SSH server

This is not a beginner level process so if you do not know why you would need an SSH server, this post is not for you. Now that is out of the way, let’s begin:

  1. Grab ISO for ubuntu server from here
  2. Install it on your hypervisor or physical machine if you are old school in that way.
  3. Install openssh server:
    1. Sudo apt-get update
    2. Sudo apt-get install openssh-server
  4. Enable and Start the SSH service
    1. Sudo systemctl enable ssh
    2. Sudo systemctl start ssh
    3. (to check it is running) sudo systemctl status ssh