问题
I want to copy some file to a remote Linux system from my Windows PC using pscp
(from putty). I wrote a small script that call the pscp commands in this way:
"C:\Users\hp\Desktop\pscp.exe" -scp C:\Users\hp\Desktop\scripts\* root@192.168.1.177:/root/scripts
"C:\Users\hp\Desktop\pscp.exe" -scp C:\Users\hp\Desktop\scripts2\* root@192.168.1.177:/root/scripts2
pause
But when I launch this bat script, I'm asked to input the password, so I input the password manually.
Is there a way to input the password automatically through the batch file?
回答1:
From putty documentation
5.2.2.6 -pw passw login with specified password
If a password is required to connect to the host, PSCP will interactively prompt you for it. However, this may not always be appropriate. If you are running PSCP as part of some automated job, it will not be possible to enter a password by hand. The -pw option to PSCP lets you specify the password to use on the command line.
回答2:
pscp -pw yourPasswordHere C:\Users\testUser\Downloads\test.sh testUser@123.123.123.123:/home/testUser
I've noticed that no one posted sample of that command with -pw option.
回答3:
You can work this stuff out for yourself. Use the /?
option to see the help. The pertinent parts are included below.
>pscp /? PuTTY Secure Copy client Release 0.60 Usage: pscp [options] [user@]host:source target pscp [options] source [source...] [user@]host:target pscp [options] -ls [user@]host:filespec Options: ...... -l user connect with specified username -pw passw login with specified password ......
Use the -l
and -pw
options to specify a user and password.
So whilst that answers the specific question that you asked, the real opportunity for you is to learn how to obtain documentation from command line utilities.
回答4:
Use putty to set up a remote login without a password. This will involve the puttygen command. You will need a private key and the target will need a public key. Once you verified that you have a good private key file and login without typing a password, you can reference it with the "-i" private key option on pscp. You might be able to set up the key without the putty connect if it isn't allowed, but this is the easiest way. Just say no to passwords in the clear:
C:\Users\riglerjo>pscp -i .ssh\rigler_rsa.ppk test.txt rigler@rigler.org:.
test.txt | 0 kB | 0.0 kB/s | ETA: 00:00:00 | 100%
回答5:
sshpass -p'password' pscp -A -H "ip" -t 20 -l root /var/www/html/temp_santosh.txt /tmp/
You can use sshpass
with -p
option just before pscp
来源:https://stackoverflow.com/questions/23080097/command-to-automatically-input-password-for-pscp