Monday, August 19, 2013

How to change the command prompt 'host & user color

[ To change the color of  'hostname' in command prompt ]

You can change the color of your shell prompt. To make your own life quite easy while working at the command prompt. Your current prompt setting is stored in a shell variable called PS1. There are other variables too, like PS2, PS3 and PS4.


Bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters.


* Task: Display current BASH prompt (PS1)

# $ echo $PS1

Sample outputs:

[\\u@\h \\W]\\$

    or

 \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
  By default the command prompt is set to [\u@\h \W]\$. The backslash-escaped special characters are decoded as follows:

    \u: Display the current username .
    \h: Display the hostname
    \W: Print the base of current working directory.
    \$: Display # (indicates root user) if the effective UID is 0, otherwise display a $.

* Task: Add colors to the prompt.

To add colors to the shell prompt use the following export command syntax: '\e[x;ym $PS1 \e[m'
Where,

    \e[ : Start color scheme.
    x;y : Color pair to use (x;y)
    $PS1 : Your shell prompt variable.
    \e[m : Stop color scheme.

* To set a red color prompt, type the following command

$ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "
A list of color codes
Color Code
Black-0;30
Blue-0;34
Green-0;32
Cyan-0;36
Red-0;31
Purple-0;35
Brown-0;33
Blue-0;34
Green-0;32
Cyan-0;36
Red-0;31
Purple-0;35
Brown-0;33

Note: You need to replace digit 0 with 1 to get light color version.

*Task: How do I make the prompt setting permanent?

 Your new shell prompt setting set by $PS1 is temporary i.e. when you logout setting will be lost. To have it set every time you login to your workstation add above export command to your $HOME/.bash_profile file or $HOME/.bashrc file.

$ cd
$ vim .bash_profile


        or 

$ vim $HOME/.bashrc    

add this line in the end of the this file.

export PS1="\e[0;31m[\u@\h \W]\$ \e[m"

(save and quit from the file )

This will permanent color change

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

For RHEL/Centos

 go to the file

#vim  .bashrc

 and edit in end of the page this line:-

export PS1="\e[0;34m[\u\[\033[0;36m\]@\[\033[0;31m\]\h\[\033[0;33m\] \w]# \e[m"

 [ and save and quit the file ]

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

For Ubuntu

*************
  go to the file

$vim  .bashrc

#force_color_prompt=yes           [ remove the '#' singh from the line ]

use this line :-

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[0;32m\]\u\[\033[0;34m\]@\[\033[0;36m\]\h\[\033[0;31m\]:\[\033[0;33m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$

[ after this save and quit the file ]

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

Sunday, August 18, 2013

LINUX-NETWORKING-COMMAND

**********************************************************************************************************************************************************************
                            NETWORKING-INFO-COMMANDS
                        ****************************************
                       
#arp-scan  --interface=eth0/1  192.168.3.0/24   [ To scan all the ip and MAC in LAN ]

#arp-scan  --interface=eth0/1   192.168.3.0/24   |grep   IP/MAC/Any word 

$nmap -v -sP  192.168.1.0/24                  [ Scan your server for open ports and up hosts ]

$sudo /sbin/mii-tool                                 [ to find the connectivity of network link is ok or not ]

$nm-tool                                                  [ Network Manager tool to find the details of the network ]

$findsmb                                                  [ find the running samba-server in the LAN from client]

$findsmb -r                                              [ from the root ]

$wget  -p                                                 [ download the any thing from the command mode ]

$netstat -ant                                            [ all establish network on our system and server ]

$netstat  -an |grep  nfs                            [ to find out the connection established with 'nfs' ]

$netstat  -nte                                           [  ]

$netstat  -ant     |grep  23

#ss  -a                                                     [ another utility to investigate sockets ]

#ss  -l

#ss -o

#ss -s

#ss -4  state  all 

#system-config-network-cmd                 [ all about network ]

#ntsysv                                                   [ to edit and show all runing services ]

#setup                                                    [ " ]

$ls  /etc/sysconfig/networking/devices  [ to check the lan card ]

#tcpdump  -i  eth0  'udp' port  53          [   ]

#strace                                                  [ trace system calls and signals]

#ciptool   -h                                           [ Blue-tooth Common ISDN Access Profile (CIP)]

#ciptool  search                                    [ search the Blue-tooth devices ]

#ciptool   show                                     [ show the devices ]

#ciptool   connect                                 [ connect the blue-tooth devices ]

#ciptool   release

#ip  link

#ip  route

#ethtool   eth0/1

#route

#route -n

#route -e

#mtr                                                       [ a network diagnostic tool ]

#       
**********************************************************************************************************************************************************************
Q. When i try to ssh our server its syas error : "RSA host key has been change for (your system ip) and Host key verification failed .


Ans. : - Add correct host key in known_hosts, multiple ssh host keys per host-name.

        1. Get the rsa key of your server.

        #ssh-keyscan  -t  rsa  serve_ip

        (you will get sum key like 'AAAAB3.......' then you copy this key from server_ip till last )


        2. And on the client add this key to  " ~/.ssh/known_hosts "

        #server_ip  ssh_rsa AAABnX.....   ( past here the coyed key and enter )
       
        (Now you can access your server from 'ssh' it will not ask you the key )



$rpm -qa \*-release\*                                [ all new release package from red-hat ]

$cat /etc/redhat-release                           [ os release ]

$ rpm -qa yum\* rpm-\* python | sort      [ all the packages of yum server ]

$ls /etc/yum.repos.d

$cat /etc/yum.conf                                    [ To find the all configuration of the yum server ]

$yum repolist all                                       [ all the repos list  ]

$rpm -qa kernel\* | sort

$ ip    link                                                  [ to check link of the ip ]

$ man  ip                                                   [  to find more option of  IP link ]  

#mtr                                                          [ a network diagnostic tool ]

#mtr -i  IP address                                  [to find about any particular ip's status]

# man mtr

#route -n                                                   [ to find the route getway ip ]

#man  route                                              [ all about 'route' ]

#netstat   -ant

#netstat    -ant  |grep  23

#
  
--------------------------------------------------------------------------------------------------------------------------------