Solved

Linux, scp and sshpass

Posted on 2013-12-20
1
2,017 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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