Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Tuesday, August 19, 2014

Three Special Permission in Linux - SUID, SGID & Sticky Bit.

Three special permission in linux are SUID, SGID and Sticky Bit which is use to control the linux user in advance.



What is SUID?

The common explanation given for SUID is, it is an advance file permission SUID allows an user to execute a script as if the owner of the script is executing it.

Example for SUID

root@linuxstorages:~#ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 22984 Jan  2006 /usr/bin/passwd

SUID bit is set on an executable. It runs with the permission of its owner.

Command :

root@linuxstorages:~#chmod u+s  < file name >

                                  or

root@linuxstorages:~#chmod 4755  < file name >


What is SGID?

If the set gid bit on directory entry is set, file in that directory will have the group ownership as the directory, instead of than the group of the user that created the file.

Command :

root@linuxstorages:~#chmod g+s  < file name >

                                 or

root@linuxstorages:~#chmod 2755  <file name >


What is Sticky Bit?

Before set the sticky bit permission for folder, the irrespective of the users has rights to delete the folder. If the sticky bit permission set for the folder, respective of the user has rights to delete the folder.

Example for Sticky Bit

root@linuxstorages:~#ls -ld /tmp
drwxrwxrwt 32 root root 36864 Mar 27 12:38 /tmp

Command :

root@linuxstorages:~#chmod o+t  < Dir Name >

                                   or

root@linuxstorages:~#chmod 1777 < Dir Name >

Monday, July 21, 2014

User Modification Commands in Linux

The usermod command modifies the system account files to reflect the changes that are specified on the command line.



User Modification Commands :

#usermod -c <Add comment>              - To change the comment for user.

#usermod -d <Home directory>           - To change the user home directory.

#usermod -u <UID>                               - To change the user id.

#usermod -g <Initial group>                  - To change initial group.

#usermod -G <Supplementary group> - To add sub group.

#usermod -l <Login name >                 - To change the login name.

#usermod -s <shell>                             - To change the shell.

#usermod -L <User name>                  - To lock the user account.

#usermod -U <User name>                 - To unlock the user account.

SYNTAX

To Add the Comment Entry

root@linuxstorages:~#usermod -c <Comment> <User name>
 To change the home directory

root@linuxstorages:~#usermod -d <Home Directory> <User name>

To change the user ID

root@linuxstorages:~#usermod -u <New UID> <User name>

To change the group ID

root@linuxstorages:~#usermod -g <Existing GID> <User name>

To add users to a supplementary group

root@linuxstorages:~#usermod -G ls2  ls3  [Adding user ls3 to group ls2]

root@linuxstorages:~#usermod -G ls2  ls1  [Adding user ls1 to group ls2]

To change the user's login name

root@linuxstorages:~#usermod -l <New Login name> <User name>

To change a user's shell

root@linuxstorages:~#usermod -S /sbin/nologin <User name>

Alternate way of changing a shell is by giving command in prompt as chsh

root@linuxstorages:~#chsh <User name>

To lock user's password

root@linuxstorages:~#usermod -L <User name>

To unlock a user's password

root@linuxstorages:~#usermod -U <User name>

To delete a user [This will not remove the user's home directory]

root@linuxstorages:~#userdel <User name>

To delete a user including home directory

root@linuxstorages:~#userdel -r <User name>

Monday, May 26, 2014

Linux Commands - 4

This article explains some of the most used Linux commands and their basic usage which will be more helpful for beginners. All these commands should be entered at the command prompt and you must press the ENTER button to execute the desired command. Please note that all Linux commands are case sensitive.

31. rpm command

To install mysql using rpm

root@linuxstorage:~#  rpm -ivh mysql-server-5.5.i386.rpm

To upgrade mysql using rpm.

root@linuxstorage:~#  rpm  -uvh mysql-server-5.5.i386.rpm

To uninstall/remove mysql using rpm.

root@linuxstorage:~#  rpm -ev mysql

32. yum command 

 To install mysql

root@linuxstorage:~#yum install mysql -y

To upgrade mysql

root@linuxstorage:~#yum update mysql

To uninstall/remove mysql

root@linuxstorage:~#yum remove mysql

33. apt-get command

 
 To install mysql

root@linuxstorage:~#apt-get install mysql-server

To upgrade mysql

root@linuxstorage:~#apt-get update mysql-server

To uninstall/remove mysql 

root@linuxstorage:~#apt-get remove mysql-server

34. su - switch user. we switch to different users account in system using su command in terminal.Super user can switch to any other user without entering their password.

 root@linuxstorage:~#su - username

only su will change to root user.

 username@linuxstorage:~#su

35.  less-  less is very efficient while viewing huge files, as it doesn’t need to load the full file while opening.

 root@linuxstorage:~# less data.log

36. tail - tail use to view last 10 line in file.it's use full for viewing log files.

 root@linuxstorage:~#tail data.log

Print N number of lines from the file

root@linuxstorage:~#tail -n 20 data.log

now we can see last 20 line in that file.

37. whatis - Whatis command displays a single line description about a command.

root@linuxstorage:~#whatis cp
cp                   (1)  - copy files and directories
cp                   (1p)  - copy files

38. ps  - ps command is used to display information about the processes that are running in the system.

To view current running processes

root@linuxstorage:~#ps -ef | more
 UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 09:11 ?        00:00:00 /sbin/init
root         2     0  0 09:11 ?        00:00:00 [kthreadd]
root         3     2  0 09:11 ?        00:00:00 [migration/0]
root         4     2  0 09:11 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 09:11 ?        00:00:00 [migration/0]
root         6     2  0 09:11 ?        00:00:00 [watchdog/0]
root         7     2  0 09:11 ?        00:00:00 [migration/1]
root         8     2  0 09:11 ?        00:00:00 [migration/1]
root         9     2  0 09:11 ?        00:00:00 [ksoftirqd/1]
root        10     2  0 09:11 ?        00:00:00 [watchdog/1]
root        11     2  0 09:11 ?        00:00:00 [events/0]
root        12     2  0 09:11 ?        00:00:00 [events/1]
root        13     2  0 09:11 ?        00:00:00 [cgroup]
root        14     2  0 09:11 ?        00:00:00 [khelper]
 more




to view particular service process id

root@linuxstorage:~#ps -ef |grep httpd
root      1871     1  0 09:11 ?        00:00:00 /usr/sbin/httpd
apache    2356  1871  1 10:26 ?        00:03:25 /usr/sbin/httpd
apache    2357  1871  0 10:26 ?        00:01:43 /usr/sbin/httpd
apache    2358  1871  0 10:26 ?        00:01:52 /usr/sbin/httpd
apache    2359  1871  0 10:26 ?        00:02:09 /usr/sbin/httpd
apache    2360  1871  0 10:26 ?        00:02:32 /usr/sbin/httpd
apache    2361  1871  0 10:26 ?        00:02:17 /usr/sbin/httpd
apache    2362  1871  0 10:26 ?        00:02:35 /usr/sbin/httpd
apache    2363  1871  0 10:26 ?        00:00:35 /usr/sbin/httpd
apache    3057  1871  0 12:47 ?        00:00:13 /usr/sbin/httpd

39. pgrep - pgrep is an acronym that stands for "Process-ID Global Regular Expressions Print".

pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. pgrep is handy when all you want to know is the process id integer of a process.


root@linuxstorage:~#pgrep httpd
1871
2356
2357
2358
2359
2360
2361
2362
2363

40. kill - Use kill command to terminate a process.First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.

First find the process id using below command

root@linuxstorage:~#pgrep httpd
1871

now kill that process id

 root@linuxstorage:~#kill -9 1871

Friday, May 23, 2014

Linux Commands - 3






This article explains some of the most used Linux commands and their basic usage which will be more helpful for beginners. All these commands should be entered at the command prompt and you must press the ENTER button to execute the desired command. Please note that all Linux commands are case sensitive.

21. uname     - Print system information.

root@linuxstorage:~#uname
Linux

22. uname -a  - Print whole system architecture.

root@linuxstorage:~#uname -a
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

23. uname -r   - Print system kernel version.

root@linuxstorage:~#uname -r
2.6.32-358.el6.x86_64

24. uname -m   - Print system os is 64 or 32 bit architecture.

root@linuxstorage:~#uname -m
x86_64

25. uname -n   - Print system hostname.

root@linuxstorage:~#uname -n
localhost.localdomain

26. hostname   - Print or set system name.

root@linuxstorage:~#hostname
localhost.localdomain

27. shutdown   - Shutdown linux system.

root@linuxstorage:~#shutdown

28. init 0     - Shutdown linux system.

root@linuxstorage:~#init 0

29. reboot   - Restart linux system.

root@linuxstorage:~#reboot

30. init 6     - Restart linux system.

root@linuxstorage:~#init 6

Linux Commands - 2

This article explains some of the most used Linux commands and their basic usage which will be more helpful for beginners. All these commands should be entered at the command prompt and you must press the ENTER button to execute the desired command. Please note that all Linux commands are case sensitive.






11. cat   - Concatenate and print (display) the content of files.

root@linuxstorage:~# cat newfile

This file have list of data.

12. echo  - Display message on screen.

root@linuxstorage:~# echo newfile

newfile.

13. clear - Clear terminal screen.

14. df    - Display free disk space of whole file system.

root@linuxstorage:~#df

Filesystem           1K-blocks         Used              Available          Use%  Mounted on

/dev/sda2            151189708     9336308      134173400           7%     /

tmpfs                      1858556             216          1858340           1%     /dev/shm

/dev/sda1                3120456        97448           2864496           4%     /boot

15. df -h   - Display free disk space of whole file system in human readable.

root@linuxstorage:~#df -h

Filesystem            Size    Used   Avail    Use%   Mounted on

/dev/sda2             145G  9.0G   128G    7%        /

tmpfs                    1.8G  216K     1.8G     1%     /dev/shm

/dev/sda1             3.0G   96M    2.8G    4%        /boot

16. du -h - Display space used by specific directory in human readable and list what all files,sub-directory available in that directory and all there space used in details .

root@linuxstorage:~#df -h

8.0K    ./.gnome2/keyrings

16K     ./.gnome2/accels

4.0K    ./.gnome2/panel2.d/default/launchers

8.0K    ./.gnome2/panel2.d/default

12K     ./.gnome2/panel2.d

44K     ./.gnome2

4.0K    ./Templates

4.0K    ./Pictures

324M    .

17. du -csh - Display only total space used by specific directory in human readable.

root@linuxstorage:~#df -csh

324M    .

324M    total

18. exit   - Exit the command prompt shell.

19. free   -  Display memory usage.

root@linuxstorage:~#free

                 total             used           free         shared    buffers     cached

Mem:       3717116    1837284    1879832          0     225776    1041684

-/+ buffers/cache:       569824        3147292

Swap:      8290296          0          8290296

20. free -m - Display memory usage in human readable(MB).

root@linuxstorage:~#free -m

                    total       used       free     shared    buffers     cached

Mem:          3629       1794       1835          0        220       1017

-/+ buffers/cache:        556        3073

Swap:         8095          0          8095

Thursday, May 22, 2014

Linux Commands -1

This article explains some of the most used Linux commands and their basic usage which will be more helpful for beginners. All these commands should be entered at the command prompt and you must press the ENTER button to execute the desired command. Please note that all Linux commands are case sensitive.

FOR VIDEO CLICK HERE

1.   pwd   - Present working directory. It show currently which path you are working on.

root@linuxstorage:~# pwd

/home/user/Desktop

2.   ls       - List Directory Contents. It will list all files and folder in current working directory.

root@linuxstorage:~# ls

data1  data2  data.txt

3.    ll       - Long Listing. It will list all files and folder with it details (permission, ownership) in current working directory.

root@linuxstorage:~# ll

rwxr-xr-x 3 root root 4096 May 10 11:14 data.txt

drwxr-xr-x 2 root root4096 May 13 09:42 data1

4.   ls -la   - Hidden files. List the content of folder, including hidden files starting with ‘.’.

root@linuxstorage:~# ls -la

data1 data2 data.txt   .cache .gvfs .bashrc

5.   cd      - Change Directory. We can able to change one to other folders with help of this command. cd without any parameters changes to the user's home directory.

root@linuxstorage:~# cd /home/user/Desktop

root@linuxstorage:~#pwd

/home/user/Desktop

6.   mkdir  - Creating new folder.

root@linuxstorage:~#mkdir data3

root@linuxstorage:~#ls

data1 data2 data3 data.txt

7.   touch  - Creating new file.

root@linuxstorage:~#touch newfile

root@linuxstorage:~#ls

data1 data2 data2 data.txt  newfile

8.   cp     - Copy. It copies a file from one location to another location.

root@linuxstorage:~# cp /home/user/Desktop/data1 /home/user/

9.   mv    - Move. It moves a file from one location to another location.

root@linuxstorage:~#mv /home/user/Desktop/data1 /home/user/

10. date  - The “date” (Date) command print the current date and time on the standard output, and can further be set.

root@linuxstorage:~# date

Fri May 17 14:13:29 IST 2013.

 

© 2014 Linux Storages | Updated . All rights resevered. Designed by Templateism