0

I have created a working script that I need to modify. The script is very simple.

cd /d path 

echo put *.pdf | sftp user@ip_address. 

del *.pdf

I'd like to find a way to do not write down the user inside the script, so system will request username and password, not only the password.

If it is not possible, it may work for my scope to find a way to setup a default user in the server so I do not write the username on the script and system will know the user.

Is there a way to connect to the host without entering the username, so system will request it?

If I enter just sftp ip_address I will get back user@ip_address password: where the user iss the local user from the client machine but it wont accept the password.

Thanks.

0

2 Answers 2

1

I do not think you can make OpenSSH tools not pickup local username automatically.

But you can make your batch file prompt for username and pass it to the sftp:

set /p "SSH_USERNAME=Username: "
echo put *.pdf | sftp %SSH_USERNAME%@example.com
0

You can go other way. OpenSSH tools always read user-controlled configuration from ~/.ssh/config (where ~ refers to your profile, in Windows, I believe, that's something like C:\Users\Username). You can configure usernames and many other things there:

Host some-nickname
    HostName 192.0.2.5
    User my-user

Then, ssh some-nickname will do ssh [email protected], and sftp some-nickname will work as sftp [email protected]; other OpenSSH tools will behave in a similar manner. Things you can put in this "per-host" configuration (actually you can refer to a group of hosts at once): identity file (which private key to use to authenticate with), known hosts file, ciphers, key exchange mechanisms, port forwards, stream commands (to run SSH connection through proxy), and many others; see man ssh_config for a complete list.

By the way, key-based authentication is great for automation, so I strongly suggest you to not make script to ask for anything (including password) but to generate a key pair and make that key restricted on the server, so only sftp is permitted with it; then, use the key-based authentication in a script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .