Sunday, 6 January 2013

Changing Command Prompt For Root Users

What about root prompt?
 That was a query posted in comments section of an earlier article,  Change Command Prompt. openSUSE does a good job of showing the root prompt in red , to warn it's users that they are in danger of corrupting their system if they are not careful. The default prompt when i change to root user using "su" command is as shown below.
Default Root Prompt
 I am going to answer this from the perspective of openSUSE 12.2 / GNOME 3.4.2 . I open the file "/etc/bash.bashrc" and read the comments section which is as follows:-
# PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes
# will be lost during system upgrades.  Instead use /etc/bash.bashrc.local 
 I acted upon the advice and create a new file in "/etc" using the command "touch /etc/bash.bashrc.local".
create bash.bashrc.local
 I add the line PS1=$ to this new file and then re-open the command prompt in root mode but the red highlighting is gone. I just see a static dollar '$' prompt.
add PS1 to bash.bashrc.local
 To get the red highlighting back i search for relevant code in "/etc/bash.bashrc". I add  the relevant lines to "/etc/bash.bashrc.local" as shown below and check the prompt again and find that the blood red prompt is back.
_bred="$(path tput bold 2> /dev/null; path tput setaf 1 2> /dev/null)"
_sgr0="$(path tput sgr0 2> /dev/null)"
PS1="\[$_bred\]$\[$_sgr0\]"
unset _bred _sgr0
unset _u _p _t
Customise PS1 variable to show red highlight
 After messing around the code in "/etc/bash.bashrc.local" i brought back the dynamic customised blood red '$' prompt back using the following lines
_bred="$(path tput bold 2> /dev/null; path tput setaf 1 2> /dev/null)"
_sgr0="$(path tput sgr0 2> /dev/null)"
PS1="\[$_bred\]\h:\w $\[$_sgr0\]"
unset _bred _sgr0
unset _u _p _t
Customise  PS1 variable make it dynamic

Twitter Account hacked

Twitter hack Direct Message (DM) bit.ly link
 I had recently received a direct message in Twitter with a bit.ly link. When i clicked on the link it weirdly redirected me to twitter login page even though i had logged in earlier. Today i noticed that there were lot of phony tweets posted by me in my profile. I realised that my Twitter account had been hacked. I remembered that I had also replied back to that direct message. I saw a lot of similar direct messages today in my account which i promptly deleted. I immediately  changed my password and removed all the Applications that have been authorised by me earlier. These two were the most important steps listed by Twitter Help article. It also asks the users to remove any phony tweets not made by the user and also delete all the direct messages too.

Saturday, 5 January 2013

Change Command Prompt

  Command Prompt is a non-graphical interface that allows you to interact with your operating system. This article deals with changing command Prompt in openSUSE 12.2 , GNOME 3.4.2. The command prompt in Unix is the famous '$'.The default command prompt in openSUSE looks like the following screenshot.
Default Command Prompt openSUSE
 The openSUSE command prompt contains information about the current user  (mantis), Host Name (linux-u7wa), Current working directory (~) which is the home directory indicator. Since the command prompt is dynamic in nature, when one changes directory the prompt also changes. Fox example if you navigate to Desktop directory then the command prompt will also change accordingly as shown below.
Dynamic Command Prompt
 In Linux the command prompt is defined in a variable called "PS1". When we run the echo against variable PS1 it will display its value. The contents of PS1 will look something like $(ppwd \l)\u@\h:\w>
echo PS1
 We can change the command prompt by changing the value in variable PS1. To change prompt to '$'  we can use the command (PS1=$) as shown below.
set PS1 value
 But setting the variable value in terminal is not permanent in nature. The command prompt will revert back to default value after the terminal is closed. To change the prompt to '$' every time you open the terminal, you need to locate the file ".bashrc" in home folder and add a line (PS1=$) at the end of the file as shown below.
set PS1 bashrc
 If you want to retain the dynamic prompt with minor changes then you need to add the line (PS1="$(ppwd \l)\u@\h:\w$") in the file ".bashrc". Here the '>' at the end is replaced by a '$' in the default prompt.
set PS1 bashrc change dynamically variable
Also check out:- Changing Root Command Prompt