Solved

Linux, scp and sshpass

Posted on 2013-12-20
1
1,920 Views
Last Modified: 2013-12-20
I am using RHEL 6.5

If I perform the following command:

# sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts
#

Open in new window


It does not return an error, but the file is never actually copied.

I understand the problem is that the site was not authenticated, as I receive the following error if I do not use sshpass:

# scp /etc/hosts root@xxclnt16:/home/hosts                   
The authenticity of host 'xxclnt16 (10.14.1.18)' can't be established.
RSA key fingerprint is ef:e3:f8:71:cf:47:8b:1c:df:fa:82:ce:48:2a:66:92.
Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'xxclnt16,10.14.1.18' (RSA) to the list of known ho...

Open in new window


Why doesnt the command with sshpass report an error.  This would be quite helpful.  Is there any way to get it to report an error

Thanks
0
Comment
Question by:Los Angeles1
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39732032
sshpass does not report error messages which go to the tty (the operation principle of sshpass is intercepting tty input/output), so you will not see any message (except for the "man-in-the middle" warning which does not go to the tty).

As far as I know the only way to deal with situations like yours is to inspect the returncode of sshpass.

Your particular problem should set a returncode of '6', so you could do

sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts

if [[ $? -eq 6 ]]; then
  echo "Host Key Unknown"
   # perform any desired action
fi


These are the returncodes of sshpass according to its manpage:
       
    1 Invalid command line argument
    2 Conflicting arguments given
    3 General runtime error
    4 Unrecognized response from ssh (parse error)
    5 Invalid/incorrect password
    6 Host public key is unknown. sshpass exits without confirming the new key.
The mentioned "man-in-the-middle" issue will produce a returncode of 255.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now