Disk Space and Partitions on Linux and UNIX-like systems

Disk Space

We can check out free disk space on a Linux system with the command:

df -h

or

df -k

These commands are great for checking overall disk space usage, but since we usually want to check which folder (or file) occupies the most disk space, we can run the command:

du -sh * | sort -hr

The first part of the command (left side of the pipe) will return the list of files and folders with corresponding disk usage values.

The second part (right side of the pipe) will sort the results by size (disk space usage) and will put the largest sizes on the top of the list. If you want the largest sizes on the bottom, just remove the 'r' parameter (r - reverse).

This command will list only the files and folders in the path where you are located, when running this command.

A suggestion:

Run the command, then 'cd' into the largest directory and run the command again. By doing that a few times, you will most likely find the source of your largest files and directories.

 

Disk Partitions

List all partitions and check their size:

sudo fdisk -l /dev/sda

Open Linux partition editor in terminal:

sudo cfdisk

Configure SSH to connect to a Remote Ubuntu Server

1. On your Windows machine I suggest installing Cmder console emulator, visit http://cmder.net/ and then download and install the Full package (with git-for-windows)

2. Open Cmder or other console software on your Windows machine, navigate to root directory, create .ssh directory and enter it

cd ~
mkdir .ssh
cd .ssh

3. Create SSH key pair id_rsa & id_rsa.pub (-t is type, -b is bytes, -f is filename)

ssh-keygen -t rsa -b 4096 -f id_rsa -C "email@domain.com"

4. Display the public key on the screen, select the printed text and copy it to clipboard

cat id_rsa.pub

5. Login to your Ubuntu Server and install OpenSSH in case you don't have it yet

sudo apt-get install openssh-server

Before you do that, don't forget to update the repositories with:

 sudo apt-get update

6. On your Ubuntu Server machine, navigate to root directory, create .ssh directory and enter it

cd ~
sudo mkdir .ssh
cd .ssh 

7. Create a file authorized_keys and open it for edit

touch authorized_keys 
nano authorized_keys 

6. Paste previously copied public key and paste it to this file

7. Logout from Ubuntu Server and try to login from your Windows machine

ssh username@192.168.1.100

(use your own Ubuntu Server root username & IP address)

8. If you're connecting to eg. GitHub via SSH, test your connection with this command:

ssh -T git@github.com

Copy public SSH key to your server

When you create SSH key pair on your computer, you can copy the public key to your server via terminal (console).

cat ~/.ssh/id_rsa.pub | ssh username@192.168.1.100 'cat >> .ssh/authorized_keys && echo "Key copied"'