Brandon - Free Palestine
Brandon - Free Palestine

Reputation: 16666

Error out instead of asking for passphrase with SSH

I'm writing a script that uses rsync, and I want it to error out if the SSH key has a password, telling the user to use a non-password protected key instead (as the script runs in the background).

However, none of the flags I've tried for SSH do this, and I've found nothing in the man pages.

What's the best way to disable the passphrase prompt for SSH?

Upvotes: 0

Views: 59

Answers (1)

acer123
acer123

Reputation: 326

You can do this using the BatchMode option. This will cause SSH to avoid anything that may cause a script to hang, such as password/passphrase prompts.

This example is taken directly from a similar question asked at http://www.unix.com/programming/184775-test-ssh-but-do-not-return-password-prompt.html

if ssh -o BatchMode=yes "$hostname" true 2>/dev/null; then
    echo "it works"
else
    echo "it's broken."
if

Here's an example with rsync:

rsync -e "ssh -o BatchMode=yes -i /var/www/.ssh/id_rsa" /path/to/test/file.txt remotehost:/path/to/test/file.txt

Upvotes: 3

Related Questions