avasdream@home:~#

Linux Basics

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.

Directory Content
/bin Common binaries shared by the system
/boot Start up files and the Kernel
/dev References to Hardware
/etc System configuration files
/home Home directories of the users
/lib Library files
/misc For miscellaneous purposes
/mnt Standard mount point
/net Standard mount point remote file systems
/opt Third-party software
/porc virtual file system. Information about system resources is stored here.
/sbin Binaries shared between the system and the system administrator
/tmp Temporary files
/usr Binaries, Libraries etc for user related programs
/var Variable 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:

Character File type Explanation
- Normal File or hard link Files that contain text or data
d Directory Data structure that contains other files
l Symbolic link Reference to other files on the system
s Socket Files for inter process communication between environments/networks
p Named pipe Files for inter process communication
b Block device Allow buffered access to system hardware components
c Character device Allow 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:

Characters Integer Value Binary Representation Permissions
rwx 7 111 All
rw- 6 110 Read and write
r-x 5 101 Read and execute
r- - 4 100 Read only
-wx 3 011 Write and Execute
-w- 2 010 Write only
- -x 1 001 Execute only
- - - 0 000 None

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!