0

I call a script from cron job. In the script it needs to run CVS commands to update from a remote repository. To do that, it needs to SSH authenticate.

I put the following code in the script

...
ROOTPATH="/Users/qazwsx/project/"

cd $ROOTPATH

SSHAGENT="${ROOTPATH}ssh-agent.cf"

if [ -f "$SSHAGENT" ]; then
    rm "$SSHAGENT"
fi

ssh-agent -s | head -n 2 > "$SSHAGENT"

if [ -f "$SSHAGENT" ]; then
        echo "$SSHAGENT"
        source "$SSHAGENT"
        ssh-add
        #function killsshagent {
    #    /bin/kill $SSH_AGENT_PID
    #}
    #trap killsshagent EXIT
    rm "$SSHAGENT"
fi
...

But when the script is run, a window as the following show up:

enter image description here

and I could NOT type anything into the input field. So the steps after the SSH authentication did not successfully run because the SSH access was not established. I'm wondering what I should do to do CVS update in cron job.

2

You could create another keypair, without a passphrase:

$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/cvs_rsa.id

Then add the contents of ~/.ssh/cvs_rsa.id.pub to authorized_keys in the remote host. You should then be able to "ssh -i ~/.ssh/cvs_rsa.id user@remotehost" from your script.

Note that when creating a key without a passphrase, anyone who has the private key file will be able to log in as you. Use with caution!

Update: from the ssh-keygen (1) man page:

 ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-f output_keyfile]

 -b bits
         Specifies the number of bits in the key to create.  For RSA keys, the minimum size is 768 bits and the default is 2048 bits.  Generally, 2048 bits is considered sufficient.  DSA keys must be exactly 1024 bits as speci‐
         fied by FIPS 186-2.  For ECDSA keys, the -b flag determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits.  Attempting to use bit lengths other than these three values for
         ECDSA keys will fail.

 -t type
         Specifies the type of key to create.  The possible values are “rsa1” for protocol version 1 and “dsa”, “ecdsa” or “rsa” for protocol version 2.

So, essentially the command says, make a 4096 bit RSA key and store it as cvs_rsa.id in the .ssh directory in the current user's home directory. ~/.ssh/ expands to $HOME/.ssh/ for whatever value of $HOME is set.

1
  • Could you please break up the command a bit and explain what each part does? – qazwsx Jan 29 '15 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.