Thursday, August 11, 2016

Linux Profile


[root@localhost ~]# vi /etc/profile


i) PATH ------------------Specific path given

ii) HOSTNAME ------------To check host name & change host name

iii) Histsize -------------------To change history commands count

iv) /etc/Inputrc -------------Keyboard mapping

v) /etc/profile.d/*.sh ------ Multiple scrip run after login you can locate this under this path .sh extension (u can create harry.sh or any this and give .sh extension for script run after login )

Source /etc/profile or ./etc/profile --------After run this command no needs to logoff or reboot system.


[root@localhost ~]# vi /etc/profile


# System wide environment and startup programs, for login setup

# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you

# are doing. It's much better to create a custom.sh shell script in

# /etc/profile.d/ to make custom changes to your environment, as this

# will prevent the need for merging in future updates.

    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then           ---------------------------Set User Specific PATH
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}

HOSTNAME=`/bin/hostname 2>/dev/null`   -------------------if u want to change host name
                (We can manage)
HISTSIZE=1000---------------------------------------------history commands count to be change
                                                                                            (We can manage)

    umask 002    ---------------------------------------------------normal user
else
    umask 022   -------------------------------------------------------root user


[root@localhost ~]# vi /etc/inputrc     ------Keyboard related command

You can enable and disable case sensitive keys in this file


[root@localhost ~]# vi /etc/profile.d/harry.sh ------------------ Multiple scrip run after login you can locate this under this path .sh extension (u can create harry.sh or any this and give .sh extension for script run after login )

--------------------------------------------------------------------------------------------------------------------
[root@localhost profile.d]# vi /etc/profile.d/harry.sh

Create harry.sh file and under this file type below script

Example
1) echo 3 | sudo tee /proc/sys/vm/drop_caches


2) swapoff -av

swapon –av


3) free –m


[root@localhost profile.d]# source /etc/profile ---------------after this cmd no need to reboot

--------------------------------Example : Result of after login----------------------------------------

3 -------------------------------------------------------------- Execute clear history cmd
swapoff on /dev/sda3-----------------------------execute swap on & off and on cmd

swapon on /dev/sda3-----------------------------execute swap on & off and on cmd

----------------------------------Execute free-m-----------cmd--------------------------------------

swapon: /dev/sda3: found swap signature: version 1, page-size 4, same byte order

swapon: /dev/sda3: pagesize=4096, swapsize=2113929216, devsize=2113929216

total used free shared buffers cached

Mem: 992 191 801 0 0 33

-/+ buffers/cache: 156 835

Swap: 2015 0 2015

-------------------------------------------------------------------------------------------------------------------

/etc/bashrc – Under 2 files


i) Umask -

user umask 002 default permission set 775

root umask 022 default permission set 755


ii) PS1

To Change PROMPT_COMMAND

--------------------------------------------------------------------------------------------------------------------
[root@localhost /]# vi /etc/bashrc

if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then

umask 002 ----------------------normal user - 199 greeter than to set 002 permission

else

umask 022 - -------------------root user -default

user umask 002 default permission set 775

root umask 022 default permission set 755

--------------------------------------------------------------------------------------------------------------------

1) Profile – User related changes ( eg -Path related changes, History command )

2) /etc/bashrc - Shell related changes (eg –umask, If you change any thinks in this file its will reflect to all users)

--------------------------------------------------------------------------------------------------------------------
[root@localhost hary]# cd /home/hary/ ----go to user specific profile and change the below .bash_profile

[root@localhost hary]# ls –a -----------------------------------to check hidden files

. .. .bash_history .bash_logout .bash_profile .bashrc .gnome2


If you change specific user go to vi /home/hary(user name)/.bash_profile

If you change in logout permission go to vi /home/hary(user name)/.bash_logout

--------------------------------------------------------------------------------------------------------------------
If you used through graphic then to used run level 5 --------IMP

If you used through command line then to used run level 3-------IMP


--------------------------------------------------------------------------------------------------------------------

Step 2: Use the hostname utility

Change your hostname to a different name of your choosing. For example:
hostname server01

Step 3: Edit /etc/hosts
Open the /etc/hosts file with your favorite text editor. For example:
nano /etc/hosts
Change the first line and replace your old hostname with the new one. Save the file and exit the editor.

Step 4: Edit /etc/sysconfig/network
This file also contains your hostname. Open the /etc/sysconfig/network file with your favorite text editor.
Change HOSTNAME=vultr to your desired hostname. For example: HOSTNAME=server01.

Step 5: Check your hostname
Run the following command to check your new hostname:
hostname
The new hostname will be displayed in your ssh terminal.

--------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment