1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in
Image:Imbox notice.png The ControlTier Wiki has moved. The new location is: http://wiki.controltier.org/

OpenSSH on Windows

From controltier

Jump to: navigation, search

ControlTier's ability to automatically coordinate distributed command execution is built on a Secure Shell (SSH) protocol "network".

The assumption is that the system user account on a given system used to run a given "dispatchCmd" from ControlTier (usually from the administration node running Jobcenter) has been "equivalenced" to all client users and systems necessary to allow non-interactive authentication via SSH. This is usually achieved using public key authentication.

While it is a fair bet that a given Unix/Linux system will be running the SSH server to enable login services, this is almost never the case for Windows systems.

This posting captures the (unfortunately complex and arcane!) steps necessary to deploy an OpenSSH server on a Windows system. The goal is to enable the SSH service, enable a designated Windows user for remote access and facilitate command execution using the command shell (cmd.exe). (These notes do not deliver a full Cygwin installation, just the minimum necessary to enable SSH access).

The notes are an updated version of a posting to the ControlTier Google group.

Contents

SSH installation

  • Download the latest version of copSSH - this packaging of OpenSSH and Cygwin provides a GUI based installer that simplifies Windows installation.
  • Run the copSSH setup program as a user with Administrators group membership.
  • Install to "C:\copSSH" or "C:\cygwin" rather than the default location (make sure that there are no spaces in any of the Cygwin paths).

User setup

  • Create or designate a Windows local (not domain based) system account as the ControlTier user.
  • Set a password for the user, and set its home folder to the Cygwin installation hierarchy, e.g.: "C:\copSSH\home\user"
    • To set the Home Folder in Windows XP:
      1. Navigate to: Control Panels > Administrative Tools > Computer Management
      2. Expand the System Tools > Local Users and Groups. Click on "Users"
      3. Right-click the chosen user account, and choose "Properties"
      4. Click on the "Profile" tab
      5. Under the Home Folder section, enter the new path under "Local Path: "
  • Log on and off once as the user to ensure settings are established, running a "cmd" shell to confirm that the HOMEDRIVE/HOMEPATH has indeed been set correctly.

Enable SSH for the user

  • Run copSSH's "01. Activate a user" item from the start menu.
  • Select the "user" and leave the default command shell for the time being.
  • Change the user's shell to "/bin/cmd.sh"
  • Deselect the options to create public key authentication keys and link the user's real home directory.
  • Create the following script in the Cygwin "bin" directory (e.g. "C:\copSSH\bin") using Notepad or similar:
C:\copSSH\bin>type cmd.sh
#!/bin/bash
if [[ $# -eq 0 ]]
then
   exec /cygdrive/c/windows/system32/cmd /Q
else
   shift
   exec /cygdrive/c/windows/system32/cmd /Q /C "$@"
fi

Convert the script to a Unix style text file as follows:

C:\copSSH\bin>d2u cmd.sh
cmd.sh: done.

Test the SSH login using a password from a remote system:

$ ssh build@myhost.mydomain
build@myhost.mydomain's password: 
Last login: Thu Apr 10 08:11:49 2008 from 10.10.1.30
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\copSSH\home\build>whoami
myhost\build

Note:

  • Unfortunately, there is no full-screen editor that works directly over the SSH terminal window to the Windows server. Either edit files locally using WordPad (which understands Unix text files) and the "d2u" program as necessary, or scp configuration files off to a remote Unix/Linux system for editing.

Create a Unix text "authorized_keys" file (no extensions) in the users ".ssh" directory containing the public key of the remote ControlTier user that will administer the box (usually from the ControlTier server). Confirm that it is possible to ssh to the account on the system from the equivalenced account on the ControlTier server and authenticate using public key (i.e. without interactively provided a password):

$ ssh build@myhost.mydomain pwd
/home/build

Note:

  • When ssh'ing into Windows system (e.g. using Putty) be careful about how the backspace character is mapped. The Windows command shell expects "Control-H". Using other characters can cause spurious characters to be embedded in file and directory names, etc.

Configure the environment

  • By default, the SSH daemon/service does not support setting custom environment. Edit SSH daemon's configuration file (e.g. "C:\copSSH\etc\sshd_config") and set "PermitUserEnvironment yes".
  • Create an "environment" file in the user's ".ssh" directory containing the following variables required by the ControlTier client:
C:\copSSH\home\build\.ssh>type environment
JAVA_HOME=C:\Java\jrockit-R27.4.0-jdk1.5.0_12
CTL_HOME=C:\ctier\pkgs\ctl-1.2
CTIER_ROOT=C:\ctier
CTL_BASE=C:\ctier\ctl

Note:

  • The values of these variables will change with future upgrades and will be specific to your installation choices.
  • Use the "Advanced" tab of the "System Properties" control panel to add the CTL bin directory "c:\ctier\pkgs\ctl-1.4.3\bin" directory to the "Path" system environment variable
  • Restart the "copSSHD" service to pick up the changes.
  • Ssh into the box as the user user and check that the variables are "set" in the command shell.

Windows version-specific notes

Windows XP

Following this process on XP required me to modify the windows firewall since it was actually On.

I did the following:

Start ->ControlPanel ->NetworkConnections ->ChangeWIndowsFirewallSettings ->Exceptions

Click Add Port

  • Name: sshd
  • Port number: 22
  • TCP selected

Click OK

Windows Server 2003

Deploying copSSH to Windows Server 2003 has revealed an issue specific to that variant of Windows.

Since Windows Server 2003 needs full credentials (username and password) to "switch effective user", automatic command execution using PKA authentication does not work using the general configuration described in this posting.

A future enhancement will modify ControlTier's Node type to store usernames and passwords as distinct attributes and supply them to Ant's SSHExec task thereby obviating the need for PKA to automate command execution.

Meanwhile, I've followed these instructions to switch the user who runs the SSH service to the application owner account required by my project.

While not completely satisfactory, this approach at least allows PKA to continue to be used while guaranteeing that commands run as the desired user account.

Despite the complexity of these notes you may concede the relief not having to reboot the Windows server to make it all work!

Personal tools