Index syndication
comment syndication

Vim Split tips

I use vim a lot of the time, mostly with splits and diffs, so the following key mappings and functions really helped me with managing the split windows. Maybe they will help you too. (Thanks to the Vim tips wiki for these).

  • If you use vertical splits, this will help move left and right across the split. Put in your ~/.vimrc

    " Map multi window keys
    set wmw=0
    " CTRL-H move to left window
    nmap h
    " CTRL-L move to right window
    nmap l
  • When scrolling up and down a window, you can use zz to jump the current line to the middle of the window. If you want this on always ala Scroll locking, then you can use this function. It is a toggle option. use \zz to toggle it. Put in your ~/.vimrc

    " Map \zz to lock scroll to middle of window
    map zz :let &scrolloff=999-&scrolloff
  • In a window split (of any sort) if you want to maximise to the current window, this will do it for you. When you press CTRL-W then o it will maximise the current view, then when pressed again will return your split arrangement! Put in your ~/.vimrc

    " Max/unmax splits
    nnoremap O :call MaximizeToggle ()
    nnoremap o :call MaximizeToggle ()
    nnoremap :call MaximizeToggle ()

    function! MaximizeToggle()
    if exists("s:maximize_session")
    exec "source " . s:maximize_session
    call delete(s:maximize_session)
    unlet s:maximize_session
    let &hidden=s:maximize_hidden_save
    unlet s:maximize_hidden_save
    let s:maximize_hidden_save = &hidden
    let s:maximize_session = tempname()
    set hidden
    exec "mksession! " . s:maximize_session

Always encrypt your ssh private key

Recently someone I know advised other IT people to generate their SSH keypair using the default options “using just enter to answer all the questions”. This means that the Private Key generated has no password against it (and is unencrypted).

In this case your private key is stored unprotected on your own computer, and anybody who gains access to that will be able to generate signatures (login to servers) as if they were you They will be able to log in to your server under your account.
I’ll reiterate that: This will allow ANYONE holding this file to access ANY server AS YOU where you have uploaded the public keys.

This means that in the case your laptop or computer is lost or stolen, your unix accounts are effectively compromised.

For this reason, your private key is recommended to be encrypted when it is stored on your local machine, using a pass phrase of your choice. To minimise this risk you should choose a strong pass phrase to be applied to the private key when generation occurs.

There are two ways to generate a key pair.

  1. If you are using openssh then generate the keypair under your unix login as follows:

    $ ssh-keygen -C "My development key 05 May 2008" -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/lantrix/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase): **type in a strong password here**
    Enter same passphrase again: **retype in your strong password here**
    Your identification has been saved in /home/lantrix/.ssh/id_rsa.
    Your public key has been saved in /home/lantrix/.ssh/
    The key fingerprint is:
    1a:aa:bb:44:09:38:ec:1d:1c:2d:27:c8:cc:dd:ee:ff My development key 05 May 2008
    $ cat ~/.ssh/ >> ~/.ssh/authorized_keys

    Then copy ~/.ssh/id_rsa the password protected and encrypted private key to a secure place on your client machine to use (placing it in your ~/.ssh/ folder – remember to set permissions to 600).

    If you want to use this openssh keypair with putty on a windows client, you will need to follow an extra step. Use PuttyGen menu to load your generated “id_rsa” file you transferred to your windows client.

  2. If you are only going to use putty to connect to UNIX servers it is better to generate the keypair in putty
    See the putty documentation for instructions on generating your key pair.
    Ensure you export the public keyfile to ~/.ssh/authorized_keys on each UNIX server you want to login (and chmod 600 on the file).

A Helpful tip

You can use putty to “cache” your key (to prevent constant retyping of your password when logging into servers) in a secure fashion using this component of putty.

Dont think of SSH keypairs as a means of easier logins. When used correctly it will in fact provide a more secure login; as your password is never passed over the network.

Mailing attachments from the Solaris Shell

I needed a quick way to send some files from the command line when logged into a Solaris server via ssh.
This assumes the server is already configured to deliver your smtp mail. I also used mailx for the sending client.
Here is how I did it, for your geeky reference.

First write your message:
cat << EOF > /tmp/mailmsg
Hi this is a message
And this is the second line

Then populate your recipient list, comma delimited as per the mailx(1) man page:
cat << EOF > /tmp/mailrecipients,

  • Then the actual command that will send your mail
  • . You need to uuencode your binary attachments, and you can send as many as you need.
    (cat /tmp/mailmsg ; uuencode /path/to/file.txt file.txt ; uuencode /location/of/otherfile otherfile) | mailx -s 'Subject' -r `cat /tmp/mailrecipients`

    You need to specify each file name twice, once for source file to encode, and once for the encoded file name; as per the uuencode(1C) man page. If you are sending from some local account on the server, the -r switch allows you to specify an alternate return address for the recipients (in other words your normal email address).

    PS: watch for the quotes and backticks. Dont mix them up!

    Hope this helps you out someday.

    Clearcase Tips Number 03 – managing label conventions with perl

    I previously showed you how to use a shell script with Rational Clearcase, to alert you when a new branch type was created.

    In this post, I will show you how to use a Perl script to enforce Clearcase labeling conventions. Perl LogoThis example is directed toward Clearcase on UNIX (i.e. Solaris or similar) and assumes you have Perl installed, working and have a basic knowledge of how to program in Perl. It is a reworked version of the windows script supplied by IBM on Developerworks.

    This is a long post, but a good one if you are a new clearcase admin who needs to enforce label names.

    Read the rest of this entry »

    « Previous entries · Next entries »