I've got a sh-script for a backup
scp /mybackupdir/* backupuser@backupserver:/backup
Is there an easy way to add a passphrase to the scp? Or do I have to check if an ssh-agent is running and if not start one and add the key?
I've got a sh-script for a backup
scp /mybackupdir/* backupuser@backupserver:/backup
Is there an easy way to add a passphrase to the scp? Or do I have to check if an ssh-agent is running and if not start one and add the key?
You can't provide passphrase to scp with argument.
However you can use authentication by key: ssh-keygen will generate rsa keys pair for authentication ssh-copy-id will copy your public key to another host.
if you can't or don't want to use authentication by keys then you can write expect script and provide passphrase from this script. It's not most secure way of implementing this!
First, let's sort out some factoids that are easy to confuse:
In the context of SSH, when people use the term ...
... but of course that is only a convention and a great source of confusion.
That said, I try to answer your question:
In case you mean password-based SSH authentication:
In case you mean publickey authentication with a passphrase-encrypted private key file:
You should read this post:
3 Steps to Perform SSH Login Without Password Using ssh-keygen
and you can change your script to this:
rsync --rsh='ssh -p(Type your SSH port)' -av /yourBackupDir backupUser@backupserver.example.com:/backup | mail -s "backup on `hostname`" your@email.account
You don't need ssh-agent for publickey authentication. You can simply pass the required key to ssh or scp with the -i
command line argument.