How to pass password to scp?
Use sshpass:
sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path
or so the password does not show in the bash history
sshpass -f "/path/to/passwordfile" scp -r user@example.com:/some/remote/path /some/local/path
The above copies contents of path from the remote host to your local.
Install :
- ubuntu/debian
apt install sshpass
- centos/fedora
yum install sshpass
- mac w/ macports
port install sshpass
- mac w/ brew
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
just generate a ssh key like:
ssh-keygen -t rsa -C "your_email@youremail.com"
copy the content of ~/.ssh/id_rsa.pub
and lastly add it to the remote machines ~/.ssh/authorized_keys
make sure remote machine have the permissions 0700 for ~./ssh folder
and 0600 for ~/.ssh/authorized_keys
If you are connecting to the server from Windows, the Putty version of scp ("pscp") lets you pass the password with the -pw
parameter.