WinSCP authenticate to the server in automation mode, using the public key authentication - scripting

I am using WinSCP to automate the copy process to server and the authentication is only with username and password.
Script is:
open username:password#ipaddress:portno -hostkey=<hostkey>
Whereas now the authentication mode has to be changed to public key.
Script changed for authenticate through public key:
open username#ipaddress:portno -privatekey=mykey.ppk
Passphrase for the private key is requested after executing the above script, but is there any way that the passphrase of the private key can be provided in the same command?

Use the -passphrase switch of the open command.
See also WinSCP FAQ
How can I connect without entering private key passphrase each time?
Also, note, that you still should use the -hostkey switch.
open username:password#ipaddress:portno -hostkey=... -privatekey=... -passphrase=...

Related

Calling gpg from SAP via external command - skipped: No public key

I am able to call gpg installed on the SAP application server and run commands like --help successfully. All public keys have been trusted and the encryption works from the command prompt on the Windows server. However, when I try to encrypt a file from SAP via SM69 I receive error "skipped: No public key".

Specifying private key on PuTTY command-line

I know there are simple commands to login to remote machine through VBA i.e. by specifying User#hostname and -pw option to provide the password in Wshell.Run function where Wshell is CreateObject("WScript.Shell").
However I need to use private key file (specified under Connection/SSH/Auth option in PuTTY) while logging in through Excel-VBA macro. Is there a way to do it?
I need it because I am using admin account on the second form of my VBA code (First form is using user's own account) and hence cannot provide the password textbox on the second form. Hence the only secure solution is to use SSH login through public and private key.
Thanks in advance!
Use the -i switch to specify the private key.
putty.exe username#example.com -i mykey.ppk
See PuTTY command line documentation.

libssh trying to authenticate with public and private keys

I've been trying to use libssh to connect to a server and download files via SFTP. I have a PuTTY private key file containing 6 lines of key for the public key and 12 for the private key yet I can't find any decent help or documentation of taking these keys and using them to authenticate a connection to the server. Does anybody know how to do this?
So far the only options for authentication I can find are what I found in the libssh header file:
LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey);
However, I don't know how a key from a PuTTY .ppk file can translate into an ssh_string for the public key or a ssh_private_key for the private key.
Use the ssh_userauth_privatekey_file instead, or see a libssh code for how it is implemented (it calls the ssh_userauth_pubkey internally).
int ssh_userauth_privatekey_file(ssh_session session,
const char *username,
const char *filename,
const char *passphrase);
You will need to convert your .ppk file to OpenSSH format using PuTTYgen (Conversions > Export OpenSSH key).
Please go through the below link, it has the solution for this problem:
http://social.technet.microsoft.com/wiki/contents/articles/20974.biztalk-server-2010-how-to-use-blogical-sftp-adapter.aspx
Just install a Bitwise SSG server.
Go to Manage host.
Import your private key.
Then select the same private key and click on "export" option.
Pop-up will ask the format for key to export, click on openSSH format.
Save the new key with extension as .ppk in your local.
Now give this key as input to BizTalk SFTP adapter. It will connect to the SFTP Server.

JSch: Checking a private key file passphrase before trying to connect

For quite a simple application that mostly depends on ssh connections made via JSch, I wanted to ask for the passphrase at the login screen, try to decrypt the private key and if it is wrong, go back to the login window.
I could not find the way to discover whether an invocation to
jsch.addIdentity(keyfile, prvkey, pubkey, passphrase);
ended properly, even if I can see in the code that the decryption has already been tried, and I suppose it already knows the passphrase is wrong.
Is there any way to detect the passphrase is correct BEFORE attempting to establish any session?
Thank you.
You can use KeyPair class for your requirements as follows,
KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey);
System.out.println(kpair.decrypt(passphrase));

Public key ssh login from windows

My client provided me public key and asked me to do a ssh login. But i havent done any ssh login before. So can you please suggest me how to use public key for ssh login. I am using putty on windows
Here is a very nice tutorial on how to setup key based authentication usint putty on Windows.
http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/pka-putty.html
With SSH, public key is stored on the server and a user must have corresponding private key to log in. If this is your situation, you can specify your private key with PuTTY in one of two ways:
Configuration -> Connection -> SSH -> Auth -> Private key file for authentication
Use -i command-line option when starting PuTTY.
In both cases you need the private key in PuTTY format (.ppk). If your key is in a different format, you'll have to convert it using PuttyGen.