8

In my Linux terminal, I am using this command

sshpass -p "pass" scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop

to download a file with a password in it. Without the sshpass, I can see the download progress, but with it, it is just blank until it finishes and I can't see it.

Is there a way I can see it with sshpass?

4

I think what you ask is not easily doable, maybe even impossible with basic bash scripting.

Therefore, the following does not really answer your question but provides another approach to your problem.

Instead of using sshpass, you could use the plain scp command with a publickey authentication without password. See [1] if you don't know what it is.

If you intend to use scp in scripts for local use, this is, IMO the way to go:

  • generate a publickey without password
  • use ssh-copy-id to add your public key to the server

That's already enough to be able to run your command without any prompt:

scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop

For scripts that you want to distribute, sshpass with clear password is certainly not a good idea, you should at least use the sshpass's "-e" flag and let the user provide the password as an environment variable for better security.

In that case, the publickey approach is a little less convenient but it is still possible. If you can't afford to ask for the user of the script to create a public key, you could create a public key on the fly, copy it on the server and execute scp without any prompting:

 #!/bin/bash
 KEY="$HOME/.ssh/id_rsa_example"
 if [ ! -e "$KEY" ]; then
     ssh-keygen -t rsa -N "" -f "$KEY"
     sshpass -e ssh-copy-id -i "${KEY}.pub" me8@host.ca
 fi
 scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop

Finally there is yet the possibility to use rsync to make the progress bar instead:

$ rsync -P --rsh="sshpass -p $PASSWORD ssh -l me8" host.ca:/cmshome/me/file /home/me/Desktop

[1] https://help.ubuntu.com/community/SSH/OpenSSH/Keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.