Tuesday, December 7, 2010

BASH customizing: Spice up the way your bash looks

Display multiple colors in bash shell prompt

Add this line to your .bashrc file
# Prompt text background by orange: two lines, title is full path of pwd,
PS1='\e[42m\d \@ \! \# \[\033]0;\h:\w\007\]\u@\h:\w\e[0;0m\nbash$ '


For changing prompt line color, use values from 40 to 47 instead of 42 in "\e[42m" 

\d - the date
\@ - the current time
\! - The history number of the command
\# - the command number of this command
\u@\h -Username@hostname (Useful when you use SCP to copy files between workstations)
\w – Current working directory (Full path)
\e[0;0m - Color ends here so that your shell color is not changed after this
\n - End of line; For prompt to be in the next line so that you have more space to type
bash$ - Just a prompt word and space for you to type

 Change the prompt color using tput

You can also change color of the PS1 prompt using tput as shown below:
$ export PS1="\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\]"

Reference:
http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/

Monday, December 6, 2010

Security solution for preventing remote ssh brute force attack on OpenSUSE Linux

If you see a lot of brute force attack on your /var/log/messages file,
you may want to beef up your security. I followed these steps to keep
the nasty intruders on bay.

System-wide OpenSSH Configuration for clients is located in the file
/etc/ssh/sshd_config. Edit the file to change the default parameters.

AllowUsers username1 username2
The option AllowUsers specifies and controls which users can
access ssh services. Multiple users can be specified, separated by
spaces.


PermitRootLogin no
The option PermitRootLogin specifies whether root can log in using
ssh. Never say yes to this option.

Port 22
The default TCP port used by SSH is 22. It is understandable
therefore that practically all anonymous SSH brute force attempts are
only targeting TCP port 22. While we do not generally consider running
the service on an alternative port a reliable measure to enhance SSH
password authentication security long-term, it can offer some limited
protection. We consider this a short term hack and ideally a site with
a sound security posture would not need to change this option.

(Now you would need to ssh with -P port# flag to ssh)

MaxStartups 5
Specifies the maximum number of concurrent unauthenticated con-
nections to the sshd daemon. Additional connections will be
dropped until authentication succeeds or the LoginGraceTime
expires for a connection. The default is 10.


LogLevel INFO
The option LogLevel specifies the level that is used when logging
messages from sshd. INFO is a good choice. See the man page for sshd
for more information on other possibilities.

Friday, November 12, 2010

Sunday, October 17, 2010

Colorful BASH prompt: How to display BASH prompt with multiple colors

Add this line to the .bashrc

PS1='\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\] '


More references:

http://wiki.archlinux.org/index.php/Color_Bash_Prompt
http://www.systhread.net/texts/200703bashish.php
http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/
http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/

How to get the system information from bash command prompt

Process info
: top

  • Then A ([{shift} + A) to have multi-window process view. Do again to go back to normal view
  • Type k and input process ID (PID) to kill a process
  • Type u and input user name to get process from the user alone


Process information
: ps -Af
: ps -u username -Af


Check the free RAM available
: free -m

Hard disk and mounted file systems
: fdisk -l (as root)
: df -hT
: cat  /etc/fstab
: du -h --max-depth=1


Other Hardware info
: uname -a
: cat /proc/cpuinfo
: cat /proc/version

/proc directory contain several info
use cat to read the files in /proc such as

cpuinfo,
devices,
filesystems,
meminfo,
partitions,
swaps,
uptime,
version

: cat /proc/cpuinfo
: cat /proc/version

: dmesg | head -2

: lspci   
(as root) (controllers, etc.) (VERY good report; -v is verbose, -vv is very verbose

: lspci -tv  
(as root) shows tree

: lsusb
: lsusb -tv 
list usb devices,


Network:
: ifconfig -a


From GUI:
: ksysguard
KDE keyboard shortcut Ctrl-ESC (KDE)
New tabs can be added to monitor a variety of stuffs

Log files are stored in /var/log (in RHEL5 and other distros)
As 'root', you can view the system events in 'messages' file.
: sudo tail -20 /var/log/messages
: sudo vi /var/log/messages



A bash script for detecting the linux version and kernel is here, but may not work for all system.


#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution.

OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`

GetVersionFromFile()
{
       VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}

if [ "${OS}" = "SunOS" ] ; then
       OS=Solaris
       ARCH=`uname -p`
       OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
       OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
       KERNEL=`uname -r`
       if [ -f /etc/redhat-release ] ; then
               DIST='RedHat'
               PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/SuSE-release ] ; then
               DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
               REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
       elif [ -f /etc/mandrake-release ] ; then
               DIST='Mandrake'
               PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/debian_version ] ; then
               DIST="Debian `cat /etc/debian_version`"
               REV=""

       fi
       if [ -f /etc/UnitedLinux-release ] ; then
               DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
       fi

       OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"

fi

echo ${OSSTR} 


from: http://www.novell.com/coolsolutions/feature/11251.html 
http://www.unix.com/unix-advanced-expert-users/21468-machine.html?t=21468#post83185


Useful Vi editor commands

VI Navigation  [escape key = ]
0  [zero] = Move to beginning of line
G         = Go to end of file
5G        = Move to beginning of 5th line
u         = Undo
.         = Repeat last command
x         = Delete character
dd        = Delete line
dw        = Delete word
d$        = Delete from cursor to end of line
$ then J  = Join/append following line with current
$ then a  = Append input at end of line
A         = Append input at end of line [same as above, but one less key stroke]
i         = Insert text at cursor
/         = Bottom of screen type search string and  will move 
                 cursor to first occurrence

Replace text
 
.  :1,$s /and/AND/g
   ^^^^^   ^   ^  ^
   |||||   |   |  |
   |||||   |   |  \----------- Globally
   |||||   |   \-------------- Replace with
   |||||   \------------------ Find
   |||||
   ||||\---------------------- substitute for text
   |||\----------------------- To last line
   ||\------------------------ separator
   |\------------------------- From line "1"
   \-------------------------- ":" operator to start command processing
Useful tid bit to remove EOL characters from DOS file 
[use key sequence "" together for EOL char]
 :%s/^M$//


Write lines to new file
:1,10w abc     [puts lines 1~10 into file abc]
Change working file from current to file abc [be sure to save first]
:e abc
Read abc file into working file after cursor
:r abc


Execute command from prompt
:!cmd    [where cmd is could be a bash command]
Example ->    :r !date   [inserts time and date at prompt]
From online wiki resource: http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell

Free HD Video Editing software

KDEnlive for Linux
http://www.kdenlive.org
http://en.wikipedia.org/wiki/Kdenlive

Avidemux for Windows and Linux
http://fixounet.free.fr/avidemux/
http://download.cnet.com/Avidemux/3000-13631_4-10829933.html

Useful Linux command compilation

Set system date/time

: date -s "17 OCT 2010 13:00:00"

: hwclock -systohc



Change the time stamps of files

: touch foo


File Permissions

chmod -R ugoa =+- rwx filename
       ^ ^^^^ ^^^ ^^^     ^
       | |||| ||| |||     |
       | |||| ||| |||     \---------- file or directory
       | |||| ||| |||                 --------------------
       | |||| ||| ||\---------------- Execute
       | |||| ||| |\----------------- Write
       | |||| ||| \------------------ Read
       | |||| |||                     --------------------
       | |||| ||\-------------------- Remove
       | |||| |\--------------------- Add
       | |||| \---------------------- assign
       | ||||                         --------------------
       | |||\------------------------ All
       | ||\------------------------- Others
       | |\-------------------------- Group
       | \--------------------------- User
       |                              --------------------
       \----------------------------- Recursively 
                                      --------------------
       Usage: chmod g+w filename
 
 
From : http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell 
An excellent resource of information with clear explanations  
 
 
 

Saturday, October 16, 2010

Linux bash command online resources for beginners and experts

These are some of the useful online resources I came across while searching for some Linux bash commands to do certain specific tasks.

1) http://www.linux.org/lessons/tips/cmndline.html

Sunday, September 12, 2010

Saturday, April 10, 2010

Sony Digital Camcorder HDR CX500V vs HDR CX550V; A comparison of technical specifications and price

The technical differences between Sony HDR CX500V and CX550V as compared to the price difference.
CX500VCX550V



35mm Equivalent : 43 - 516mm (16:9), 52 - 624mm (4:3)

35mm Equivalent : Photo: 28.7 - 287mm (16:9), 26.3 - 263mm (4:3); Movie: 29.8 - 298mm (16:9), 36.5 - 365mm (4:3)
Optical Zoom : 12xOptical Zoom : 10x
Digital Zoom : 150xDigital Zoom : 120x
Shutter Speed : Scene Selection, 1/8-1/725; STD, 1/60-1/725Shutter Speed : Scene Selection, 1/8-1/1500; STD, 1/60-1/1500; LOW LUX, 1/30-1/1500; Smooth Slow Rec., 1/240-1/1500
Focal Distance : 5.5 - 66.0mmFocal Distance : 3.8 - 38.0mm
Minimum Illumination : STD, 11 lux (1/60 Shutter Speed); LOW LUX, 3 lux (Auto Slow Shutter ON, 1/30 Shutter Speed)Minimum Illumination : STD 11 lux@1/60 Shutter Speed LOW LUX 3 lux@1/30 Shutter Speed Nightshot 0 lux@1/60 shutter speed
LCD Screen : 3.0" wide touch panel3Clear Photo Plus LCD display (230k pixels)
  • LCD Screen : 3.5” Xtra Fine LCD™ display (921K)3 w/TruBlack™ technology
  • Viewfinder : Wide (color 201k)

No GPSEmbedded GPS : Yes
  • Removable Flash Media Compatibility : Memory Stick PRO Duo™

Removable Flash Media Compatibility : Memory Stick PRO Duo™ MARK2 Media and SD/SDHC (Class 4) media (Sold Separately)
  • PictBridge Compatible : No
  • Easy Operation : No

  • Direct Copy : Yes
  • Golf Shot : Yes
  • Intelligent Auto : Yes (Landscape, Backlight, Twilight, Spotlight, Low light, Macro, Portrait, Baby, Walk, Tripod)
  • White Balance : Auto, Outdoor, Indoor, One Push (via Touch panel)

maging Device : 1/2.88" "Exmor R" CMOS sensorImaging Device : 1/2.88" back-illuminated "Exmor R" CMOS sensor
  • Headphone Jack : No
  • Microphone Input : No
  • Headphone Jack : Yes
  • Microphone Input : Yes
Price(As on April 8th 2010 from any authorized dealer in the USA)
: $699
$1,199.00


Source: From official Sony website- SonyStyle.com