Hack the permissions in Linux

Many of you reached here because of the term ‘Hack’. Sorry to say, I have to disappoint you(or may be not!). Here I am just discussing about how the Linux permissions work and not anything about hacking the system in a way script kiddies think. I am just mentioning few things about how the permissions are actually working and how it can lead to unwanted results if you are not sure what you are doing. I have put some commands below and for a Linux guy, it is enough and you will get an idea what I am talking about :

root@ubuntu:~# mkdir /root/test
root@ubuntu:~# ls -ld /root/test/
drwxr-xr-x 2 root root 4096 Mar 1 15:27 /root/test/
root@ubuntu:~# useradd tom
root@ubuntu:~# cat /etc/passwd|grep tom
tom:x:1001:1001::/home/tom:
root@ubuntu:~# chown -R tom:tom /root/test/
root@ubuntu:~# ls -ld /root/test/
drwxr-xr-x 2 tom tom 4096 Mar 1 15:27 /root/test/
root@ubuntu:~# userdel tom
root@ubuntu:~# ls -ld /root/test/
drwxr-xr-x 2 1001 1001 4096 Mar 1 15:27 /root/test/
root@ubuntu:~# useradd jerry
root@ubuntu:~# cat /etc/passwd|grep jerry
jerry:x:1001:1001::/home/jerry:
root@ubuntu:~# ls -ld /root/test/
drwxr-xr-x 2 jerry jerry 4096 Mar 1 15:27 /root/test/

See how the user jerry got access to tom’s files. It was caused by the same uid both were having. So if you are dealing with a large number of users, never simply delete the user. Just disable the user or change all the permission of the user to something more suitable before removing the user.

Enjoy 🙂

Proper Permissions in Linux

It is always a bad idea to keep all the files and folders with full permissions (file : 666 and folders : 777) for the sake of getting rid of the errors. Use the below commands to find out all the files and folders with full permission under the account /home/theg :

find /home/theg -type f -perm 666 -print
find /home/theg -type d -perm 777 -print

 

Use the below command to change all the permissions to 755 for all the folders and 644 for all the files :

find /home/theg/ -type d -perm 777 -exec chmod 755 {} \;
find /home/theg/ -type f -perm 666 -exec chmod 644 {} \;

Enjoy !!! 🙂