Linux Security - PART 1
Published: 2023-07-22 13:53:24

**_<u>We are going to discuss on below Topics :
</u>_**
1. Linux Security Problems
2. Local Filesystem Security 
3. Local Authentication in Linux
4. Remote Auhentication
5. Network Security
6. Security Tools & Distros 
7. Patching a Bash Vulnerability
8. Security Monitoring & Logging 

## 1. Linux Security Problems

**_<u>Important Points to be remembered :
</u>_**
1. Remove unnecessary packages.
2. After any installation work on security aspects.
3. Always remember : 
   Accessibility ,
   Software Installation Rights , 
   Data permission and 
   Recovery from Failure 
4. Password Protection Policy
5. Integrity Checks :
   MD5 checksum - This will provide hash value which can be 
   checked for any issues.
   To use this , there is also a package : **sudo apt-get 
   install gtkhash**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdf04vf1sn6bexlqywgt.png)

**_<u>How to check user as ROOT access ?
</u>_**

useradd Linux
passwd Linux
usermod -aG sudo testing
su testing
groups
sudo whoami

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqumjnb51gpsnt1jm6v4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hw5txb0j51mgkhlhwfi0.png)

Once its populating 'root' at the last , this user as ROOT access.

**_<u>NMAP :
</u>_**

1. Scan a network.
2. Gather information about a network.
3. https://nmap.org/
4. This can check what ports are running , status , etc.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0xwo05buonl2g1e0cis.png)

## 2. Local Filesystem Security

1. ls
2. ls -FC ( directories will have '/' at the end , executables will have '@' at the last , etc )
3. ls -l
4. ls -a ( hidden files )
5. ls -lh ( size )
6. ls -d */
7. ls -lah ( always use to practice this ! )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etlcg8kejjs55944rqef.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgnxjmdb1rq96ppuvy9y.png)

<u>**chmod :**</u>

u - user/owner
g - group
o - Others

r - Read
w - write
x - Execute

Adding the permission ,

chmod u+x file_name
chmod g+x,o+x file_name
chmod o-x file_name  ( remove the permission )
chmod a+r file_name  ( a - for all users , it will provide read permission for all users like u,g,o )
chmod a-r file_name
chmod o+x -R <directory> ( R for recessive for a directory )

we can also reference one file permission to other , 
chmod --reference=file1 file2

Now OCTAL representation ,

r = 4
w = 2
x = 1

Read and Execute Permission,

r-x = 4+0+1 = 5
rwx = 4+2+1 = 7
r-- = 4+0+0 = 4

chmod 754 <file_name>

<u>**Access Control List :**</u>

1. ACL
2. Check whether ACL is installed or NOT , check using any file :
   **getfacl file_name**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3dwrjjbtuei8ifogru1n.png)

Here user3 won't have access to the directory.
We can save the permission of a directory for future purpose,
**getfacl -R /directory>permissions.acl**
We can also restore the permission, 
**setfacl --restore=permission.cal**

**<u>move command :</u>**

1. mv file_name /directory ( files will be deleted in the old directory )
2. Rename file and directory can be done with this.
3. mv -V *.txt /directory ( like Verbose )
4. mv -i file_name /directory ( it helps to notify if there is any same file_name in the target directory  , it will give a pop up )
5. mv -uv *.txt /target (TBD) Its like updating the file.
6. mv -bv *.txt /target (TBD) it will create backup file
7. mv -nv *.txt /target (TBD)














**_<u>Notes :</u>_**

1. usermod -aG (TBD)
2. what is the difference between useradd or adduser ? (TBD)
3. passwd -d username (TBD)
4. Add the user to the group , usermod -G group1 user1
5. Add group , addgroup group1