Add ssh key to remote host

Example of tunnelling an X11 application over SSH
Image via Wikipedia

If you are working on recent versions of the *nix OS like Fedora or Ubuntu then you would know about the commad ssh-copy-id. But if you land up using one of the older versions like Solaris or something where the command is not present, then probably you need a simpler solution to this. One of the simplest solution is with a lot of assumtions, simply copy the id_rsa file to remote server and hope it works. And here is  a script to do just that:

#!/bin/bash -
#===============================================================================
#
#          FILE:  add_ssh_key.sh
#
#         USAGE:  ./add_ssh_key.sh
#
#   DESCRIPTION:  Add the ssh key
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 09/19/2011 11:02:08 AM IST
# Last modified: Mon Sep 19, 2011  11:02AM
#      REVISION:  ---
#===============================================================================
ip=$2
un=$1
IFS=$"\n' key=$(cat .ssh/id_rsa.pub)
ssh $un@$ip "echo $key >> ~/.ssh/authorized_keys"

or the other option is to copy the ssh-copy-id script to the server in question. If you don’t have the script handy, I am pasting it here:

#!/bin/sh

# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.

ID_FILE="${HOME}/.ssh/id_rsa.pub"

if [ "-i" = "$1" ]; then
  shift
  # check if we have 2 parameters left, if so the first is the new ID file
  if [ -n "$2" ]; then
    if expr "$1" : ".*\.pub" > /dev/null ; then
      ID_FILE="$1"
    else
      ID_FILE="$1.pub"
    fi
    shift         # and this should leave $1 as the target name
  fi
else
  if [ x$SSH_AUTH_SOCK != x ] && ssh-add -L >/dev/null 2>&1; then
    GET_ID="$GET_ID ssh-add -L"
  fi
fi

if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
  GET_ID="cat ${ID_FILE}"
fi

if [ -z "`eval $GET_ID`" ]; then
  echo "$0: ERROR: No identities found" >&2
  exit 1
fi

if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
  exit 1
fi

# strip any trailing colon
host=`echo $1 | sed 's/:$//'`

{ eval "$GET_ID" ; } | ssh $host "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys" || exit 1

cat <<EOF
Now try logging into the machine, with "ssh '$host'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

EOF
Enhanced by Zemanta

mplayer – find all the installed codes for audio and video

MPlayer
Image via Wikipedia

Some time back, I was trying to find out all the codecs that are installed for my mplayer. These could be the ones that came with mplayer or the ones that I downloaded from the site and installed in the various directories.

I could not find a direct way to do this, until I found this:

mplayer -ac help -vc help

And here is the output of the command:

MPlayer SVN-r33996-4.6.1 (C) 2000-2011 MPlayer Team
Available audio codecs:
ac:     afm:      status:   info:  [lib/dll]
wma9dmo     dmo       working   Windows Media Audio 9 DMO  [wma9dmod.dll]
wmadmo      dmo       working   Windows Media Audio DMO  [wmadmod.dll]
wma9spdmo   dmo       working   Windows Media Audio 9 Speech DMO  [wmspdmod.dll]
wma9spdshow dshow     working   Windows Media Audio 9 Speech DShow  [wmavds32.ax
]
ffqdm2      ffmpeg    working   FFmpeg QDM2 audio  [qdm2]
qdmc        qtaudio   working   QuickTime QDMC/QDM2 audio  [QuickTime.qts]
ffqclp      ffmpeg    working   FFmpeg QCLP audio  [qcelp]
qclp        qtaudio   working   QuickTime QCLP audio  [QuickTime.qts]
qtmace3     qtaudio   working   QuickTime MACE3 audio  [QuickTime.qts]
qtmace6     qtaudio   working   QuickTime MACE6 audio  [QuickTime.qts]
zygoaudio   qtaudio   working   Zygo audio  [ZyGoAudioS.qtx]
ffra144     ffmpeg    working   FFmpeg RealAudio 1.0  [real_144]
.....
Available video codecs:   
vc:     vfm:      status:   info:  [lib/dll]
ffanm       ffmpeg    working   FFmpeg Deluxe Paint Animation  [anm]
ffbinkvideo ffmpeg    working   FFmpeg Bink Video  [binkvideo]
ffcdgraphics ffmpeg    working   FFmpeg CD-Graphics  [cdgraphics]
ffmvi1      ffmpeg    working   FFmpeg Motion Pixels  [motionpixels]
ffmdec      ffmpeg    working   FFmpeg Sony PlayStation MDEC (Motion DECoder)  [mdec]
ffsiff      ffmpeg    working   FFmpeg Beam Software SIFF  [vb][/vb]
ffmimic     ffmpeg    working   FFmpeg Mimic video  [mimic]
.......

And if you wanted to see only the audio codecs:

mplayer -ac help

or just the video codecs:

mplayer -vc help
Enhanced by Zemanta

g flag in :s useless in vim

Some time back there was a post on vim_use list about the “/g” flag for the search and replace functionality of the vim. And the response of “Tim Chase” on the same was very elaborate and interesting. I always knew that “/g” is only for replacing multiple occurrences on the same line, but here are few things that I did not know.

   :0/this/s//that

This one will only replace the first occurrence of this in the whole file.

   :-/this/s//that

This one will replace the first occurrence of this in the file from current cursor position including the current line.

And finally here is the link to the post.

Enhanced by Zemanta