openSSH is a popular tool for performing operations using SSH, SCP and SFTP. As of version 1809 of Windows 10 it actually comes bundled. Since On the current version of the desktops at TC use (version 1709), openSSH requires an installation as it is an optional feature.
Tip |
---|
DO NOT install the optional feature version of openSSH on your older version of Windows 10 as this version is not fully featured. Install the latest from GitHub as per below. |
Install Steps
Note that there are some pre-install steps that must be taken to avoid an error during the installation.
Pre-Install
...
Follow steps 1-5 from this link. If you only want the openSSH client then this is good enough. If you want to set up the openSSH server, generate keys, etc. then go ahead and look at the remaining steps.
You should now be able to type ssh, sftp, scp or any other openSSH commands into your command window.
Some Useful Info
Private Key Format
If you're using a private key with extension .ppk (Putty private key), this will have to be converted to openSSH format so that you can use it with openSSH. To do this you'll have to download PuTTY and use PuTTYGen to export your key as an openSSH key as described here.
Sample Usage
If you want to send a file securely using SFTP:
- Set up a configuration file for your sftp connection. Call it "config" and put it in a folder called .ssh under your user folder (eg. c:\Users\{your name}\.ssh).
Sample file:
Code Block language bash
...
net stop wuauserv && net start wuauserv
Install
To make sure that the OpenSSH features are available for install, run the following in powershell:
Code Block language powershell Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
This should return the following:
Code Block language powershell Name : OpenSSH.Client~~~~0.0.1.0 State : NotPresent Name : OpenSSH.Server~~~~0.0.1.0 State : NotPresent
Then, simply install the client and/or server features as follows:
Code Block language powershell # Install the OpenSSH Client Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 # Install the OpenSSH Server Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Both should return the following output:
Code Block language powershell Path : Online : True RestartNeeded : FalseHost sftp2aws HostName somehost.server.transfer.ca-central-1.amazonaws.com IdentityFile C:\Users\{your name}\Documents\sftp2aws-key User sftpaws HostKeyAlgorithms ssh-rsa Compression yes
- Host - alias name for your connection
- HostName - the actual destination of the sftp server
- IdentityFile - your private key
- User - username
Create a script holding command(s) to actually send the file.
Sample script:Code Block put c:\yourfiletosend.txt exit
Run the sftp command:
Code Block C:\>sftp -b C:\sftpScript.txt sftp2aws
Here, the -b indicates you're running the sftp command in batch mode (ie. passing in a script) and sftp2aws is the connection you configured in your config file above.
NOTE: If this is the first time you are connecting to the sftp destination you may run into a problem because you don't explicitly trust the server's identity. You may get the following message:Code Block Host key verification failed. Connection closed
The best way to add this trust is to run the ssh command on the command line and answer yes to the question Are you sure...:
Code Block C:\>ssh sftp2aws The authenticity of host 'somehost.server.transfer.ca-central-1.amazonaws.com (xx.xx.xxx.xxx)' can't be established. RSA key fingerprint is SHA256:blahblahblah. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'somehost.server.transfer.ca-central-1.amazonaws.com,xx.xx.xxx.xxx' (RSA) to the list of known hosts. Connection to somehost.server.transfer.ca-central-1.amazonaws.com closed by remote host. Connection to somehost.server.transfer.ca-central-1.amazonaws.com closed.
This will create the known_hosts file in your .ssh folder if it isn't already there, and it will add an entry for the destination. An entry in that file indicates the destination is trusted.