Operating System - HP-UX
1820591 Members
1880 Online
109626 Solutions
New Discussion юеВ

scp script prompted a password

 
SOLVED
Go to solution
Dewa Negara_4
Regular Advisor

scp script prompted a password

Hi All,

I have a script using scp with private/public keys that pull a file from around 500 servers. The script was stuck because 1 or 2 servers was not configured with proper keys and requested a password. I have to type the password manually, so that the script can continue running. How can I give the password automatically without doing it manually? or how can I skip those servers, so that the script can continue running? Is there any scp option to skip the password?

Please help. High score will be given.

Warning: Permanently added 'sihp8025,15.12.11.34' (RSA) to the list of known hosts.
secumgr@sihp8025's password:

Thanks and Best Regards,
Dewa
Santos
5 REPLIES 5
Keith Bryson
Honored Contributor

Re: scp script prompted a password

Dewa

Did you use ssh-keygen2 (as the secumgr user on the central server) to generate the public key and enter a blank catchphrase during the key generation?

Then did you copy that public file to the remote system and add it's reference to the authorization file in the user's $HOME/.ssh2 folder (on the remote server)?

Best regards - Keith
Arse-cover at all costs
Dewa Negara_4
Regular Advisor

Re: scp script prompted a password

Hi Keith,

Thanks.

Yes I did it. Most of servers were running well. What I want is that if there is a server missed the public key on ~/.ssh (for instance deleted by mistaken) when the script is running, this server will prompt a password. How can we skip this server, so the script still can be running.

Pls help.

Thanks.
Dewa
Santos
Keith Bryson
Honored Contributor
Solution

Re: scp script prompted a password

Dewa

I have a similiar job run from cron and do a test first (yours would look like this, if run from the root cron):

su secumgr -c "/usr/local/bin/ssh2 -l secumgr sihp8025 ls -al >/dev/null 2>&1"
retc=$?
if [ $retc -ne 0 ]
then
echo "Not accepting remote connections"
else
echo "Up and accepting connections"
# Anything else to do goes here
fi

Keith
Arse-cover at all costs
Denver Osborn
Honored Contributor

Re: scp script prompted a password

Use the "-B" option to enable batch mode operation. This option will not prompt for passwords. You could also use "-o PreferredAuthentications=publickey". This tells ssh to use public key auth.

Hope this helps,
-denver
Denver Osborn
Honored Contributor

Re: scp script prompted a password

To push out this file, you could do something like this...

for NODE in `cat hosts.txt`
do
echo sending $FILE to $NODE >>/tmp/scp.log
scp -i ${KEY}/${NODE} -o StrictHostKeyChecking=no -B /path/myfile ${NODE}:/path/myfile 2>/tmp/err.log 1>/tmp/scp.log
if [ $? -eq 0 ];then
echo copy to $NODE complete >>/tmp/scp.log
else
echo copy to $NODE failed >>/tmp/scp.log
fi
done


Where $KEY is the path to the public keys you use for the target hosts. ex/ ~/.ssh/keys/ dir could contain seperate public/private key pairs for all targets. Easy way to store them is by naming the pub/priv key the hostname. If you use the same public/private key pair for all nodes, use "-i /path/key_file" in the example I showed above.

Hope this example helps,
-denver