Typically when a VPS or dedicated server is provisioned Linux (and the linux file system) is used as the default operating (OS) system. Unless you opt for a windows based server linux will be the default.
Linux is an exceptionally well-designed OS that allows you to manage your server efficiently which can also prevent you from accidentally making changes to critical linux file system files.
For typical day-to-day computing you never need to venture outside of your own websites home directory, but when you want to explore deeper into the linux file system and perform administration tasks it’s a good idea to know what’s going on in the rest of the filesystem and what the different directories are used for.
Unlike a traditional home computer which uses Windows OS, which can have directories and files scattered across multiple drives (C:, D: etc), in Linux there’s just one main directory that’s the starting point for everything else.
This is called the ‘root‘ directory and is represented by a single forward slash: /.
This root directory is the deepest point you can go in the Linux file system – it’s not a subdirectory of anything else.
The Linux Directory Structure
In the Linux file system, slashes are used to separate directories, hence why a single slash on its own is the root, and not part of anything else.
As an example, in the root directory, you typically have the ‘home‘ directory, which contains a websites users’ home folders and files. This is why the default full location for your home folder is usually:
The first slash is the root directory, then you see the home directory, followed by another slash and finally a directory for your username (typically associated with your domain name).
If your using traditional linux web hosting then more often than not this directory will be your default location you have access to and you’ll most likely be ‘jailed’ to only this directory to prevent you accessing anything higher.
Of course on your own dedicated/VPS server you would have full root access letting you browse the whole directory structure freely.
A Linux installation can have multiple users on the system, so each one would have their own directory such as /home/website1, /home/website2 and so forth.
Inside of each users directory, you will have all the relevant files for that web user i.e. website files, ftp file, logs, email etc.
How to access Linux using SSH
Firstly you will need to create your SSH keys to enable a secure connection to the system. On a cPanel based system, this is fairly straightforward to do and gets you to access quickly to your linux OS.
Once you have created your keys (or you may be using password authentication, which we don’t recommend) then we usually like using WinSCP which allows you to view files and folders via a GUI. It’s easier to use than putty, which is a command line based tool, however, it’s much simpler to use commands in putty than WinSCP.
If you are a beginner then using WinSCP is probably easier until you get familiar with the directory structure.
Typical folders on a Linux System
Let’s browse around some of the other directories on the filesystem and see what they do.
Launch the program of your choice (Putty or WinSCP) and login as required. Once you’re logged in you should see a screen similar to the one below:
In the image above you’ll see that we’re in the root of the linux file system (highlighted) and we cannot go any higher up than this. The main folders located in the root / are:
/bin – Contains binary files – These are not graphical applications. Typically these are executable files that allow a minimal system to boot up. On newer installs, this may also be a symlink (symbolic link) to the user/bin folder which would contain the same files.
/boot Directory – Contains files also used for boot. In here you’ll see the kernel files that the linux OS needs to boot and kernel upgrade files. The kernel is loaded by the config files (see inside the ‘grub’ folder and the file) when the system starts. It manages memory, loads your programs and so forth.
/dev Directory – Files in this directory are system device files which communicate with a driver in the kernel, which generally, in turn, communicates with a piece of hardware installed on the system.
/etc Directory – System-wide configuration files. These files mainly contain options for users, security, power management, networking and other aspects of the system. Some applications also place their default settings in this location after installation.
/home Directory – Contains home directories as described earlier.
/lib Directory – System libraries. These are compilations of executable code that any program can use. For instance, every program written in the C language needs to use features provided by the C library: if all programs had to include it in their own executable files, there would be a lot of duplication and disk waste. Consequently, libraries are shared here. The C library shares code with almost all programs so as to keep executable sizes smaller and reduce duplication.
/lost+found Directory – In general this folder should be empty (which is a good sign) Files are dropped into this folder by the OS if the system experiences corruption as an example due to power loss and restarts abruptly. Linux will perform a disk check; if it finds any bits of data that weren’t saved properly before the power loss, it will drop them here.
/media Directory – The place where external drives appear after they’re inserted. For instance, plug in a USB key and other temporary media and a folder will appear here with its name so that you can browse it.
/mnt Directory – Mount points, where you can attach drives and network resources. It has largely been replaced by /media now.
/opt Directory – Optional software. Some large programs place their files in subdirectories in here.
/proc Directory – Process information. When you run programs, they create subdirectories in here containing information on their status – eg usage of memory and other files. Graphical system management tools can read and parse these files to present a more human-readable format.
/root Directory – Files for the ‘root (admin) user; this is not related to the root directory. Because only the root user can access this, it’s locked out. Unless you perform any actions as the root user, though, nothing happens in here.
/sbin Directory – Superuser binaries – that is, executable programs that are mostly administrative tools which can only be run as the ‘root’ admin user.
/selinux Directory – Files which provide a flexible Mandatory Access Control (MAC) system built into the Linux kernel to handle one of Linux’s security frameworks.
/srv Directory – Can be used by server software such as Apache, which holds website-specific data to be served by the system for protocols such as ftp, rsync, www, cvs etc.
/sys Directory – Provides access to system information. As with /dev, because everything in Linux is represented as a file, here you can access information on the kernel and devices (/dev contains links to the actual devices themselves). Most of these files are very cryptic, but graphical tools can load these files, parse them and show the results in a more friendly fashion.
/tmp Directory – Temporary files used by applications. This is normally purged when the system boots.
/usr Directory – All system-wide, read-only files installed by (or provided by) the OS. Whereas/bin and /lib contain important base files to be used at the command line, in /usr/bin you’ll find desktop software, and in /usr/lib you’ll find libraries and files for those programs.
/var Directory – Varying files – files which the system writes data during the course of its operation and change a lot, such as log files, databases tables etc. reside here.
In your typical day-to-day usage of linux hosting, you won’t need to poke around inside these directories at all, but it’s worth knowing exactly what they do for future reference.
You may want to install specific programs like malware scanners or firewalls like ConfigServer Security & Firewall (csf).
When you have a damaged dedicated server or VPS installation or need to perform advanced operations you can delve into these folders as required without worrying about what each folder is for!