[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: secure copy without user input



also sprach Bjarne S . Nćss (on Sat, 10 Mar 2001 01:40:17PM +0100):
> This is quite simple. Just run ssh-keygen and an empty passphrase.
> By default the key generated will be put in .ssh/identify.pub  copy
> the line into the .ssh/authorized_keys into the home folder of
> target machine, and you should be able to ssh and scp into the
> target machine without password.

except that it won't work with cron because ssh needs a controlling
tty for rsa or dsa authentication.

the only way around this i found is to write a script which implements
its own cron. i have one attached which tunnels my fetchmail through
ssh. same process (and yes, i know fetchmail has a precommand, but
this is better...)

martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
-- 
"if you stick a stock of liquor in your locker,
 it is slick to stick a lock upon your stock. 
      or some joker who is slicker,
      will trick you of your liquor,
 if you fail to lock your liquor with a lock."
#!/bin/sh

STATEDIR="$HOME/var/state"
SLEEPFILE="$STATEDIR/`basename $0`.sleep"
PIDFILE="$STATEDIR/`basename $0`.pid"

UPDATEINTERVAL=180

source $HOME/.zshenv
source $ZSHDIR/function/ssh

gettunnelpid()
{
  echo `ps e -C ssh | grep -e "-L $1" | awk '{printf \$1}'`
}

maketunnel()
{
  killtunnel $1
  echo -n "creating tunnel $1... "
  sshtunnel $1 $2 110 2> /dev/null
  [ $? != 0 ] && return 1
  echo "success (pid `gettunnelpid $1`)."
  return 0
}

killtunnel()
{
  PID=`gettunnelpid $1`
  [ -z "$PID" ] && return 0
  echo -n "killing tunnel $1 (pid $PID)... "
  while [ ! -z "$PID" ]; do
    kill -TERM $PID
    PID=`gettunnelpid $1`
    sleep 1
  done
  echo "done."
}

waitfor()
{
  DATE=`date -d "now + $1 seconds"`
  touch -d "$DATE" $SLEEPFILE
  echo "sleeping until $DATE..."
  while true; do
    sleep 5
    [ ! -f "$SLEEPFILE" ] && break
    [ `date +"%s"` -gt `stat -t $SLEEPFILE | cut -d" " -f12` ] \
      && rm -f $SLEEPFILE
  done
}

start()
{
  if [ -f $PIDFILE ]; then
    kill -TERM `cat $PIDFILE`
  fi
  echo $$ > $PIDFILE
}

finish()
{
  echo "terminating... "
  rm -f $PIDFILE
  rm -f $SLEEPFILE
  killtunnel 11000
  exit 0
}

trap finish INT QUIT KILL TERM STOP

start

while true; do
  maketunnel 11000 diamond.madduck.net

  fetchmail -qf ~/.fetchmailrc 2> /dev/null

  killtunnel 11000

  waitfor $UPDATEINTERVAL
done

finish

Reply to: