Skip to main content

Posts

Showing posts from 2015

Managing linux users

We will discuss how to create new user, modify existing user details and password. Types  of users          UID  root                               0 system                           1-999 normal                          1000-6000 System user is again divided into two types- Kernel and Application users Kernel :Like ping, shutdown have UID between 1-200 Application: Like Mysql have UID between 201-999  Adding user: Command: useradd <user> Eg: useradd star1 Note that a line will be added at the bottom of /etc/passwd file as below star1:x:1076:1078::/home/star1:/bin/bash If password not set for user then the user will be locked. Setting a password for the created user: command: passwd <user> Eg: #passwd star1 Changing password for user star1. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully.  You can switch user from one user to anothe

Sticky Bit with example

Sticky Bit is used on folders in to avoid deletion of its content by users who are in same group with the owner of the file. Before understanding the sticky bit, I recommend reading SGID post which explains its disadvantage. From SGID we understood that the user E1 can delete the file of E2 and vice versa. So to avoid this, we use sticky bit. Command To set: chmod o+t <dir> To unset: chmod o-t <dir> eg: # chmod o+t /project/ # ls -ld /project/ drwxrws--T . 2 root teamA 84 Aug 31 09:03 /project/ You will notice T in others permission. Now the user E1 cannot delete file of E2 and E2 cannot delete of E1. Below example shows E1 user trying to delete file of E2 but sticky bit didnt allow the file to get deleted. $ rm e2_file.txt rm: remove write-protected regular empty file ‘e2_file.txt’? y rm: cannot remove ‘e2_file.txt’: Operation not permitted  

SGID with example

SGID is Set Group ID. When SGID is used? Eg: You are manger of teamA and teamA has 2 engineers E1, E2.  You will be assigning a project to teamA so that all two engineers should work on this project. You will create a folder /project. teamA group is created and E1,E2 users are assigned to the group. You will set group permission of the folder as below. ls -ld /project drwxrwx---. 2 root teamA 6 Aug 31 08:39 /project Now E1,E2 can create files inside the project folder as shown below. -rw-rw-r--. 1 E1 E1 0 Aug 31 08:45 e1_file.txt -- > file created by E1 user -rw-rw-r--. 1 E2 E2 0 Aug 31 08:46 e2_file.txt --> file created by E2 user. Here the problem is E2 cannot edit or change E1 file and vice versa since the file permission for group is assigned of the user. To fix this, the group permission of the files should be changed to teamA. In other words, when file gets created permission from the project folder should be automatically assigned to files inside th

SUID with example

SUID is Set owner User ID. When SUID is used? Eg: You are a Super administator and can run commands like "fdisk -l" from root user. But what if in your absence, you want this command to run by a normal user. "fdisk -l" will not give any output when run with normal user account. One option is to give sudors permission to the normal user and then user can run the command. But there is risk in this. Sudoers will allow normal user to run all the root commands. To prevent this and allow the normal user to run only one command, SUID is used. After setting SUID for /sbin/fdisk, then normal user will be get the result for "fdisk -l" SUID info: Permission Number : 4 To set SUID: # chmod u+s <filename> To remove SUID: # chmod u-s <filename> Eg: Before permission of /sbin/fdisk ls -l /sbin/fdisk - rwxr-xr-x 1 root root 267176 Aug  5 06:55 /sbin/fdisk Setting SUID for /sbin/fdisk #chmod u+s /sbin/fdisk Now permission of /sbi

SSH/Terminal screen display

Display information during login on terminal. To display hostname and date on terminal after user login. 1. Open .bashrc file found in the home directory 2. Add below lines in at the end of the files echo "Hostname:" hostname echo "Uptime:" uptime echo "Server details:" uname -a date Now when you login  will be have following displayed on the terminal. Hostname: ajay-pc Uptime:  22:22:43 up 12:40,  7 users,  load average: 0.12, 0.12, 0.12 Server details: Linux ajay-pc 3.16.0-44-generic #59~14.04.1-Ubuntu SMP Tue Jul 7 15:07:27 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux Thu Jul 30 22:22:43 IST 2015