Wednesday, October 21, 2009

ssh-agent script

From: http://mah.everybody.org/docs/ssh



#!/bin/sh

SSH_ENV="$HOME/.ssh/environment.$HOSTNAME"

if [ -x /usr/bin/ssh-agent ]
then
SSH_AGENT=/usr/bin/ssh-agent
SSH_ADD=/usr/bin/ssh-add
else
echo "Can't find ssh-agent"
SSH_AGENT=/bin/false
SSH_ADD=/bin/false
fi

start_agent () {

printf "Starting new SSH agent... "
$SSH_AGENT > "${SSH_ENV}"
if [ $? = 0 ]
then
echo "OK"
printf "3s|^echo|#echo|\nw\n\q\n" | ed "${SSH_ENV}" >/dev/null 2>&1
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}"
else
echo "ERROR"
fi
$SSH_ADD -l | grep : || {
$SSH_ADD;
}

}
#
# Source SSH settings, if there
#
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}"
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -fu$LOGNAME | grep ${SSH_AGENT_PID}.*ssh-agent$ >/dev/null
if [ $? != 0 ]
then
start_agent;
else
$SSH_ADD -l | grep : || {
echo "Agent is running, but has no keys..."
$SSH_ADD
}
fi
else
start_agent;
fi


and add this to your .bashrc / .kshrc


alias ssh_agent='. $HOME/.ssh/ssh_agent'
SSH_ENV="$HOME/.ssh/environment.$HOSTNAME

Installing a local copy of git

# To build & install your own local copy of git:

wget -N http://kernel.org/pub/software/scm/git/git-1.6.5.1.tar.gz

# (link from http://git-scm.com/ )

tar xf git-1.6.5.1.tar.gz
cd git-1.6.5.1

#
# Turn off support for OpenSSL (used for IMAP over SSL)
# and curl (used for http: and https: repositories)
# These two seem to be broken on Red Hat
#
NO_OPENSSL=1
NO_CURL=1
export NO_OPENSSL
export NO_CURL

#
# You probably don't want to use the default of your home dir
# because it creates 5 dirs for git:
# $ ls ~/git
# bin lib lib64 libexec share
#
./configure --prefix=$HOME/git
make
make install

# then add $HOME/git/bin to $PATH

# Read this:
#
# http://www.kernel.org/pub/software/scm/git/docs/everyday.html
#
# And you should be sorted.

Wednesday, October 14, 2009

To export your PuTTY and WinSCP sessions

You can export your settings for these apps from regedit:

PuTTY:

HKEY_CURRENT_USER\Software\SimonTatham

WinSCP:

HKEY_CURRENT_USER\Software\Martin Prikryl

Tuesday, October 13, 2009

Copying and pasting in screen

When you're in screen and want to copy something...

Go
<Ctrl>-A [
Then move to where you want to mark, using your vi keys hjkl or the arrow keys.
Press
<Enter>
to set the first mark.
Select the block you want to copy by moving to the second mark
then press
<Enter>
to copy the selected text to the buffer

Then to use the selected text...

Say you want to cat it into a file...


$ cat > file


Then go
<Ctrl-A> ]
to paste.

This also lets you go back up into your scrollback.

http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer/ is a good HOWTO for this.


$ cat ~/.screenrc
vbell_msg '*ding*'
vbell off
defscrollback 20000
scrollback 20000
compacthist on

Monday, October 12, 2009

protocol error: mtime.sec not delimited

If you get an error saying:


protocol error: mtime.sec not delimited


When you are using scp to send files to a machine...

Check the login process on that machine to see what messages are being echoed to STDOUT when you login.
If you can get rid of the message (e.g. by not running fortune or doing 'echo "blah"') then the error should go away.

If it's something you want to run on an interactive login, then you could put a test around it to only run it then...

e.g.


if [ $TERM == "xterm" ]; then
fortune -s
fi

Thursday, October 01, 2009

vi change on matching lines

If you'd like to do something globally on lines that match a string,
without needing to do anything to the string itself...

e.g. find all lines matching <img src=".*> and append </a>


:g/<img src=".*>/s%$%</a>%


This says:

globally match <img src=".*>

and on the matching lines substitute </a> for $

Tuesday, September 22, 2009

~/.ssh/config

The fields you most often need in ~/.ssh/config are...


Host HOSTNAME
User USERNAME
HostName IP_ADDRESS (or hostname.fqdn)


Not to mention the proxy stuff below.

Tuesday, September 15, 2009

Extracting files from Solaris packages

How to extract files from a DaTaStReAm package without installing the package on the system:

You use pkgtrans to convert a datastream format package to file system format.


$ pkgtrans gzip-1.3.12-sol26-sparc-local .

Thursday, August 06, 2009

Debian Lenny in qemu on Windows

http://homepage3.nifty.com/takeda-toshiya/qemu/

Create an image to install into:

qemu-img.exe create -f qcow qemu_disk.img 3G

Download install image:

http://www.debian.org/CD/netinst/


Copy and change qemu-win.bat

To boot the install image with:
qemu.exe -L . -m 128 -hda qemu_disk.img -soundhw all -localtime -M -cdrom debian-503-i386-netinst.iso

Then to run normally, remove the -cdrom part.

I have also used: -m 256 -cpu pentium3 -M pc -no-reboot -no-acpi -no-kqemu

To do this I copied qemu-win.bat to a new batch file, and edited that to suit my needs and use that to start qemu.

There maybe a few errors when it boots, but nothing serious - and I can run it on a machine where I don't have admin, where I can't install VirtualBox or similar.

If you add:

-redir tcp:22::22
You can ssh into localhost to get into the machine.
-redir tcp:2222::22 if 22 is already in use...

Other links:
http://lassauge.free.fr/qemu/
http://www.davereyn.co.uk/download.htm ?