Improving the Windows command line

I typically use Ubuntu for development and I've gotten used to having a full-featured terminal. Moving into a Windows environment for a .NET project, I've become increasingly frustrated with the shell application. I'm not even talking about the niceties of bash, such as tab-completion and sensible colors (which can be achieved through Cygwin with minimal effort). I mean things like being unable to drag-resize the window or copy and paste in a natural way.

Today, I decided to solve my problem using two of my favorite Windows applications: Putty SSH and Cygwin.

The Goal: Instead of using the Windows command line, use a Putty terminal that connects passwordlessly to an sshd server running on localhost.

Anybody who has used ssh on Linux for any period of time has probably done something like this to allow passwordless logins between systems. The concept is pretty much the same, but the tools are different. By the way, these instructions are for XP, and I have no idea whether they would work with Vista.

  1. Get Cygwin and install it. Make sure to install the "openssh" package (under Net), and "cygrunsrv" (under Admin) in addition to the default packages.
  2. Create a new system variable (by right-clicking "My Computer", selecting "properties", going into the "Advanced" tab, and clicking the "Environment Variables" button) with name "CYGWIN" and value "ntsec tty".
  3. Add Cygwin to your PATH: from the "Environment Variables" screen, select the PATH variable, click the "edit" button, and append ";C:\cygwin\bin".
  4. Set up the SSH server by opening a Cygwin window and running "ssh-host-config -y". When it asks you for "environment variable CYGWIN", enter "ntsec tty".
  5. Start the server by running "cygrunsrv --start sshd".
  6. Now make sure that Cygwin can correctly read the Windows users on the box. Make sure every account has a password (which you should do anyway), then run the following commands in a Cygwin window:
    mkpasswd -cl > /etc/passwd
    mkgroup --local > /etc/group
  7. You should now be able to SSH into your local server by entering "ssh localhost" in the Cygwin shell. You should be asked for your password, and then you should be logged in.
  8. Now time to set up Putty! Download Putty.exe and PuttyGen.exe from here.
  9. Open up PuttyGen, make sure "SSH-2 RSA" is selected at the bottom, and click "Generate".
  10. Save the private key somewhere.
  11. Select and copy the public key text.
  12. SSH into your local server (using Cygwin or putty, doesn't matter) and paste the public key into ~/.ssh/authorized_keys2 (create this file if it doesn't exist).
  13. Exit the SSH session and open Putty again. Click "Session" from the left column. Enter "localhost" under "Host Name".
  14. Go to the "Data" screen (under "Connection" on the left side) and put your Windows username where it says "Auto-login username".
  15. Go to the "SSH" screen (again, under "Connection") and make sure SSH protocol version is set to 2 (not "2 only").
  16. Expand "SSH" in the left navigation pane and go to the "Auth" screen. Under "Private key file for authentication", browse to your private key.
  17. Go back to the "Session" screen and save these settings (enter a name under "Saved Sessions" and click the "Save" button). You should now be able to open this session and connect without a password!
  18. Last but not least, create a shortcut to Putty that automatically loads that session. If you create a shortcut to Putty, change its target (right-click the shortcut and select "Properties") by appending -load "SessionName". Include the double-quotes around "SessionName" and change it to the name of your saved session.

There you go! Double-clicking that shortcut should open up a terminal to your local SSH server. You now have the power of bash on your Windows machine, but it's running inside of a sensible terminal!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.