Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: SSH SFTP connection + command + SSH Password

If you want to authenticate using private key without Pageant, you need to specify your private key using -privatekey switch of open command:
https://winscp.net/eng/docs/scriptcommand_open
cgardyne

SSH SFTP connection + command + SSH Password

This is my first time connecting from WinSCP to a SFTP server and I have a few problems/questions.

Firstly I've got the process running when there's no SSH auth and the user just needs a password.

Now I'm running into a problem when SSH auth is required.

Also note that I can connect with FileZilla using a private key and the same user.

So I connect via the command script below:

option batch abort
option confirm off
open sftp://[user]@[domain] -hostkey="[hostkey]"
get -delete *.txt D:\Temp\*.txt
exit

I know the username and domain are right as I can connect without SSH auth and the hostkey is right as I have matched it to the one in the log below.

Here's the log when I connect (a lot of info removed):

. 2014-02-05 10:54:26.703 Session name: [user]@[domain] (Modified site)
. 2014-02-05 10:54:26.703 Host name: [domain] (Port: 22)
. 2014-02-05 10:54:26.703 User name: [user] (Password: No, Key file: No)
. 2014-02-05 10:54:26.703 SSH protocol version: 2; Compression: No
. 2014-02-05 10:54:26.703 Bypass authentication: No
. 2014-02-05 10:54:26.704 Looking up host "[domain]"
. 2014-02-05 10:54:26.704 Connecting to [domain] port 22
. 2014-02-05 10:54:26.759 Server version: SSH-2.0-FileCOPA
. 2014-02-05 10:54:26.759 Using SSH protocol version 2
. 2014-02-05 10:54:26.759 We claim version: SSH-2.0-WinSCP_release_5.5.1
. 2014-02-05 10:54:26.782 Doing Diffie-Hellman group exchange
. 2014-02-05 10:54:27.046 Doing Diffie-Hellman key exchange with hash SHA-1
. 2014-02-05 10:54:27.790 Verifying host key [big long key exchange]
. 2014-02-05 10:54:27.791 Host key matches cached key
. 2014-02-05 10:54:27.791 Host key fingerprint is:
. 2014-02-05 10:54:27.791 [hostkey]
! 2014-02-05 10:54:27.844 Using username "[user]".
. 2014-02-05 10:54:27.875 Prompt (7, SSH password, , &Password: )
. 2014-02-05 10:54:27.875 Disconnected: Unable to authenticate

Now my question is with regards to the lines:

. 2014-02-05 10:54:26.703 User name: [user] (Password: No, Key file: No)

and

. 2014-02-05 10:54:27.875 Prompt (7, SSH password, , &Password: )

First of all, should Key file be Yes if it requires an SSH key?

Secondly, is the password prompt for the user on the SFTP server or a passphrase for the SSH key? I turned off password required for the user in the SFTP software and when I generated my key on the server I didn't use a passphrase.

I've also loaded a public key against the user in the SFTP software, so how do I go about sending through the key from the WinSCP command line? I've added both the public and private keys to my .ssh dir.

Thanks in advance.