Published on

Linux Basics

Authors

Hello World!

If you can't explain it simply, you don't understand it well enough.

Today I will try to explain in a few words basic concepts of Linux.
Firstly let's see what are all the subdirectories of the root directory for.

DirectoryContent
/binCommon binaries shared by the system
/bootStart up files and the Kernel
/devReferences to Hardware
/etcSystem configuration files
/homeHome directories of the users
/libLibrary files
/miscFor miscellaneous purposes
/mntStandard mount point
/netStandard mount point remote file systems
/optThird-party software
/porcvirtual file system. Information about system resources is stored here.
/sbinBinaries shared between the system and the system administrator
/tmpTemporary files
/usrBinaries, Libraries etc for user related programs
/varVariable files

If you have a standard user in Ubuntu all your personal files are stored at home/USERNAME/. In Kali Linux you are by default the root user therefore all your files are at root/. Quick note: if you are new to Kali Linux I would recommend you to create a standard user to start with.

  1. adduser john Creates a new user.
  2. adduser john sudo Add the user to the sudoers group.

Everything in Linux is a file. You can see all the files in a directory by browsing to the directory and typing ls -l. This will give you output looking like this:

-rw-rw---- 1 root disk 22, 2 May 18 10:26 filename

Let us take a closer look at the output.

-rw-rw---- are the file type and the permissions.

1 is the number of links/references to the file.

root disk is the user and the group that own the file.

22 the size of the file.

2 May 18 10:26 date when the file was last modified.

filename the name of the file.

In this string -rw-rw---- the first character is the type of the file. These file types exist in Linux:

CharacterFile typeExplanation
-Normal File or hard linkFiles that contain text or data
dDirectoryData structure that contains other files
lSymbolic linkReference to other files on the system
sSocketFiles for inter process communication between environments/networks
pNamed pipeFiles for inter process communication
bBlock deviceAllow buffered access to system hardware components
cCharacter deviceAllow unbuffered access to system hardware components

The next nine characters rw-rw---- are the file permissions for this file. There are three sets of user permissions represented by three characters. The first three rw- are for the owner, the second for the group and the last set is for all users. These are all possible permissions and their representation:

CharactersInteger ValueBinary RepresentationPermissions
rwx7111All
rw-6110Read and write
r-x5101Read and execute
r- -4100Read only
-wx3011Write and Execute
-w-2010Write only
- -x1001Execute only
- - -0000None

There is also one special permission called SetUID. The suid bit is an extended file permission. If this bit is set the permission looks like this -rws. In the most cases you can find this permission on binaries. With this permission set every user can execute the binary with the permission of the owner. A bad example would be this situation where the suid bit is set on the bash binary:

-rwsr-xr-x 1 root root 1.1M Jun 17 21:15 /bin/bash

This would lead to a situation where every user can execute bash and escalate their privileges to root.

To change the permissions of a file you can use the chmod command.

chmod permission file

The permissions are represented in their integer values, also called absolute mode of chmod.

chmod 777 file leads to these permissions -rwxrwxrwx.

chmod 600 file leads to these permissions -rwx------.

If there is the need to change the owner and group of a file the chown command is there for you.

chown user:group filename

That was it for the beginning, I hope I could help someone with this post.

Happy Hacking!