How to view progress with sshpass and scp in linux?
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 [email protected]:/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" [email protected]
fi
scp -r [email protected]:/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
Related videos on Youtube
omega
Updated on September 18, 2022Comments
-
omega almost 2 years
In my Linux terminal, I am using this command
sshpass -p "pass" scp -r [email protected]:/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?