Wednesday, October 7, 2015

login shell vs interactive shell




System Wide settings  

              A shell is a shell is a shell -- e.g., a login bash shell is the same program (like /bin/bash) as a nonlogin bash shell. The difference is in the way that the shell acts:


            In a Login shell you are prompt for your Login username and password

           when you first log in to a Unix system from a terminal, the system normally starts a login shell. The login shell uses a collection of startup files to help create an environment such as environment variables, search path, and subshells.

           The files in the /etc directory generally provide global settings. If an equivalent file exists in your home directory it may override the global settings.


Login shell process:

Frist the bash login shell looks for the global settings.

It first initiates the  

/etc/profile.

The /etc/profile file provides the system wide default environment variables. Typically this sets up the umask, LOGNAME, and mail directories etc. It can also be used to change the default command search path (PATH) for all users on the system.

The /etc/profile.d Directory 

This file is actually a line in the /etc/profile. It loads are the file in the  /etc/profile.d directory, where the individual initialization scripts are placed: 

/etc/profile.d/* 

Any thing you need to modify,you don’t want to create in /etc/profile,you can create it in .sh and put it in the /etc/profile.d/ director.


So if a system updates occurred all the changes you have written in the /etc/profile got changes .but if you place files in the /etc/profile.d nothing happens to your executable  files.


/etc/bash.bashrc 

It contains the System wide aliases and functions.Personal aliases and functions should go into ~/.bashrc.it Provides colored /bin/ls and /bin/grep commands.Used in conjunction with code in /etc/profile.

These three complete the system wide settings

User wide settings

IT looks for three profile

/home/user/.bash_profile
/home/user/.bash.login
/home/user /profile

/home/user/.bashrc

This file is where you put your history length,Xterm color and alias
 
   


Here you can see ll commands returns ls –aLF

Where do I get all these ?
It all there in the /etc/skel

.bash_logout
What it does when the login shell exits it clears the console history

 Interactive shell is when you are already logged in GUI mode and open a terminal, and then you can tell that it is an interactive shell
 



Monday, October 5, 2015

Linux permissions: chown, chgrp

Changing file ownership

              As a regular user,you cannot change ownership of a file or a directory to have them belong to another user.you can change ownership as the root user.

              For ex: say you created a file and used chown command to change the ownership permission




                     The file was owned by fabien,after running the command chown sith path,the ownership changed to sith.but left the group as fabien

      To change both user and group to sith you need to type the following command.


Now you can see that both the user and the group changed to sith.

             The chown command can be used recursively as well. Using the recursive options (-R) is helpful if you need to change a whole directory structure to ownership by a particular user .

For ex: if you inserted a USB drive,which is mounted on the /media/myusb directory,and wanted to give full ownership to the contents of the drive to the user fabien,you could type the following.

#chown -R fabien:fabien  /media/myusb


Changing group ownership


            CHGRP(CHange GRouP) is the command which is useful to change group associated to a file/folder from one group to othe.

syntax : chgrp <groupname> file/folder 


 Here in this example we have change the group ownership from fabien to sith


 Change group ownership all the files located in /var/apache to group:apache
 
        #chgrp -R apache /var/apache       

Difference between chown and chgrp

1) chown command is used to change ownership as well as group name associated to different one, where as chgrp can change only group associated to it.

2) Many people say that regular user only able to use chgrp to change the group if the user belongs to them. But it’s not true a user can use chown and chgrp irrespective to change group to one of their group because chown is located in /bin folder so every can use it with some limited access.