Installing SSH-server for Windows

Back to guide list

Valid HTML 4.01 Transitional Valid CSS!
Valid 4.01 HTML & CSS
Telnet-like, but secure and encrypted remote connection server (Secure SHell) and secured ftp-like file-server (sftp / scp) available as free Open Source project, OpenSSH and running under Cygwin, Unix API for Windows.

This guide is partly based on the guide "How to install OpenSSH sshd server and sftp server on a Windows 2000 or Windows XP, but I think I could have done it myself.

This is a guide for those who want to run an SSH/SCP server under Windows for shell usage or file transfering or even running irssi under screen (yes, we're going to use cygwin to also get some traditionally *nix-only programs working under Windows. This should work under WinXP and Win2000 at least - apparently it's possible even under Win9x, but really... If you must use Windows, at least ditch that 9x! For machines not powerful enough for w2k or XP I recommend some light linux setup. Seriously.

INDEX

0. Why use Cygwin + OpenSSH?
1. What is needed?
2. Installing Cygwin
3. Configuring Windows environment variables for Cygwin
4. Configuring SSH daemon
5. Setting up accounts and passwords
6. Testing sshd
7. Accounts adding and removing

Cygwin, uh? Any other solutions?

Yes there are, but let's face it - having a UNIX like subsystem just can't make Windows any worse. On the contrary, it's an improvement. And there are serious flaws in those other solutions - let me quote SSHWindows homepage (SSHWindows is a full Windows port of OpenSSH):
The OpenSSH for Windows package provides full SSH/SCP/SFTP support. SSH terminal support provides a familiar Windows Command prompt, while retaining Unix/Cygwin-style paths for SCP and SFTP.

Windows Command prompt, eh? What a load of fun can one have in there with that humongous amount of console based tools, utilities and programs that exists for Windows? Yes, that's the problem and to my understanding it is the same for all other solutions - cygwin then again offers powerful UNIX like command line interface and loads of utilities that you can use to what you ever would want (except graphics). And as it is one of the most common usages of shell accounts I've seen to run irssi on the server - well, there is no screen nor irssi for Windows command prompt available.
NOTE! There might be one positive exception in commercial SSH-servers: Bitvise WinSSHD. It has a nice (and unnecessary, imho) GUI for setting things up, but apparently you can set the shell that remote user will have - it defaults to cmd.exe, which is that sad Windows command prompt, but you could install 4NT, powerful replacement for cmd.exe (4NT is a Windows folower of the legendary DOS command.com replacement, 4DOS) or preferrably still install cygwin and set it's default start-up program as shell.
Of course you will have to pay for WinSSHD while you could spend a little time and get your server setup in a short while for free and all by yourself.

I've heard rumours that there are some commercial closed source programs for just this purpose, but with free and excellent unix solution, OpenSSH, that can be also installed on Windows - well, why bother with those closed source solutions that may even cost a lot.

The ssh server is an emulation of the UNIX environment and OpenSSH for Windows, by Redhat, called cygwin. - This is why we are now able to run UNIX based programs (not all of them) under windows and even remotely. This is important also because SSH is a text based connection and for a reason that I dont understand Windows doesn't really have much of them and even simplest programs are built graphical - like irc-clients that really don't need graphics at all.

1. What is needed

You need to install cygwin - there is couple options:
From these two options available, plain Cygwin is enough to get Secure Shell Server and SCP file transfer server up and running, but personally I installed Cygwin/X, because it has other features I'll wan't, like X-server (the base of most known UNIX graphical desktop system) and with that a possibility to run also graphical Cygwin ports of UNIX programs and even through SSH X11-forwarding running graphical programs from remote computer through SSH on my screen. If you need anything like that, take Cygwin/X instead of plain Cygwin. If you're not sure you might wan't to study those sites.
Although to get this SSH server we're working on running you can pick any one of the two I might still recommend Cygwin/X for many reasons - one of them beeing that really good "Cygwin/X User's Guide" on their page.

Now create a directory C:\cyginstall\ and download the cygwin.exe from any of those two sites - and place it to the directory you created. We are going to start.

2. Installing cygwin

Note! You must be logged in as user with administrator priviledges. Make sure that your account (the one with administrator privilidges) has a Windows password set (many windows users for some reason don't have). If it is not, go to Control Panel and select User Accounts and make yourself a password.

3. Configuring Windows environment variables for Cygwin


Adding and modifying Windows environment variables.

4. Configuring SSH daemon


Running ssh-host-config in the same kind of window used by cmd.exe.
What is ntsec and tty

tty is an environment variable used by cygwin to make it work properly with editors such as pico and nano.
Without it (the default case), you won't be able to insert characters.

ntsec is an environment variable used by cygwin to instruct cygwin to use Windows' security rules for controlling users' access to files and other operating system facilities.
For a detailed explanation of ntsec see this page
http://cygwin.com/cygwin-ug-net/ntsec.html

Note: if you run ssh-host-config when sshd is installed, ssh-host-config will not ask for the CYGWIN value. In that case, stop and remove the sshd service, then run the ssh-host-config script again by running following commands:

$ cygrunsrv --stop sshd $ cygrunsrv --remove sshd $ ssh-host-config $ cygrunsrv --start sshd

5. Setting up accounts and passwords

Make sure that every Windows user has a password set. If not, go to Control Panel, User Accounts and create a password.

Now, under Cygwin command prompt (most likely bash shell) type these commands:

touhis@touhu1 ~ $ mkpasswd -cl > /etc/passwd touhis@touhu1 ~ $ mkgroup --local > /etc/group
If your XP logs on to a domain, you most likely have to edit /etc/group by hand. This outside webpage has a short and simple guide for it: Cygwin passwd and group.

About mkpasswd and mkgroup tools

The mkpasswd program can be used to help configure your Windows system to be more UNIX-like by creating an initial /etc/passwd from your system information. Its use is essential on the NT series (Windows NT, 2000, and XP) to include Windows security information, but the actual passwords are determined by Windows, not by the content of /etc/passwd.

For more information, see this page http://cygwin.com/cygwin-ug-net/using-utils.html#mkpasswd.

The mkgroup program can be used to help configure your Windows system to be more UNIX-like by creating an initial /etc/group. Its use is essential on the NT series (Windows NT, 2000, and XP) to include Windows security information.

For more information, see this page http://cygwin.com/cygwin-ug-net/using-utils.html#mkgroup.

6. Testing the sshd

Try the following commands to check if Cygwin is working and ssh up and running well:
touhis@touhu1 ~ $ whoami touhis touhis@touhu1 ~ $ ssh robsku@127.0.0.1 The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. RSA key fingerprint is 6a:04:fc:0e:60:98:20:0b:2c:38:6c:85:ad:05:39:f5. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts. robsku@127.0.0.1's password: Last login: Sat Oct 7 03:27:18 2006 from 127.0.0.1 robsku@touhu1 ~ $ whoami ; pwd robsku /home/robsku robsku@touhu1 ~ $ ls /cygdrive/c AUTOEXEC.BAT Inetpub System Volume Information cygwin Bootfont.bin MSDOS.SYS WINNT mgafold CONFIG.SYS NTDETECT.COM WUTemp net Config.Msi PUTTY.RND arcldr.exe ntldr DOSPelit Pelit arcsetup.exe pagefile.sys Documents and Settings Program Files boot.ini svhost.exe IO.SYS RECYCLER cyginstall winscp.RND robsku@touhu1 ~ $ logout Connection to 127.0.0.1 closed. touhis@touhu1 ~ $

Succeeded in test connection? If you did see a directory listing after 'ls /cygdrive/c', then you have succeeded!
If you have a Unix system that does not know what to do with TERM cygwin, add these scripts to .login.
If you have troubles ssh into the server, try run ssh-user-config.

Please, do use your own username on the commands instead of touhis and robsku. If your windows username has a space, you can write it in two ways. Here's a couple example commands: ssh mikko\ kuustonen@127.0.0.1 or ssh "mikko kuustonen@127.0.0.1". According to one of the webpages I read while setting this up myself if you get this error message: "ssh-exchange-identification: Connection closed by remote host" - it's propably caused by McAfee 8.0i.

7. Accounts adding and removing

Manage other Windows user accounts using the Control Panel, User Accounts.
After creating and/or removing Windows user accounts open a cygwin commandline and run following commands to set the Windows user accounts to Cygwin too:
$ mkpasswd --local > /etc/passwd $ mkgroup --local > /etc/group

Do note that users able to log in through ssh will be able to move to just about any directory.

Removing users ssh account while keeping the Windows username active

You might not want all persons with user-account for your Windows to have access right to the SSH-server. It is easy to disable. If you want to remove SSH-access from username "leetd00d", just open file /etc/passwd with a text editor (eg. nano) and remove the line that starts with the username (leetd00d).