HOEI

SSH client on Windows CMD Line

May 2nd, 2006

Are you a network administrator who is required to use a Windows operating system but are also require an SSH client to access routers, firewalls, switches, Linux, and/or UNIX. This post is targeted at network administrators needing SSHv2 (Secure Shell version 2) at the command prompt on a workstation or laptop running a Microsoft Windows operating system. There are plenty of applications on the market offering SSH and telnet in a GUI application. The problem is that many times a network administrator is at the command prompt using ping or traceroute to troubleshoot network problems. It can be distracting and even aggravating to reach for the mouse, minimize the CMD window, double click on PuTTY, select a saved session, and click open. Many network administrators, especially those who came up through the Unix or Linux ranks would much rather stay on the keyboard when they are int he heat of troubleshooting a network problem. Well here is one solution.

My solution is simple in that it provides a different way to use a popular and free Telnet/SSH client called PuTTY. The PuTTY application has many more functions than what I am using it for in this example, but I am going to focus on how to use it from the command line in Windows. This is a small example of how to make the application more useful for you when you would rather not use the mouse when needing make a Scure Shell connection from the command line of Windows. Sometimes I find myself in the middle of a help desk call at about 3AM. Someone on the other side of the planet is about to go home for the day when they realize that they still have a problem to correct. They call our help desk and they patch the call through to me if the problem is more than the level I or II engineers can handle. I drag myself out of bed and make my way to the kitchen table to fire up the laptop.

Here is my HOW TO:

  1. You need to download a copy of PuTTY if you don’t already have it. it.
  2. Rename and save a copy of the Putty.exe file to your system directory as ssh.exe. (i.e., c:\windows\system32\ssh.exe) The important thing is that you put the renamed file in a directory that is in your path statement. This step will allow for you to type ssh [IP or HOSTNAME] at a command line.
  3. Open a command window and type ssh and press your return key. The window shown in Figure 1 will appear.
    PuTTY Configuration - Main
    Figure 1
  4. Use your mouse to select Default Settings and then click the Load button.
  5. Verify that you have selected the settings as shown in the above image and then click Session\Logging option on the left side of the window. The window in Figure 2 be shown.
    PuTTY Session Logging Options
    Figure 2
  6. I have selected to have all of my sessions logged to a file. This file will be unique for each instance of PuTTY that I run. I do this logging automatically so that I can always go back to my logs later to verify that I did a wr mem on a Cisco router or switch after making changes when I was half asleep during a support call in the middle of the night. This is also insurance for me to prove that I did on a box if I get accused of making a change to a router, firewall, or VPN access control list (ACL) or route statements that broke something.Here is a sample filename from my C:\SSHLOG\ directory:2006-05-01-230229-192.168.1.56.log   Note: The What to do if the file already exists: is really not even applicable unless multiple people are writing to a network drive since the file name includes the time in military format right down to the second. I would not worry too much about drive space for standard log files from accessing routers, switches, and firewalls. I have accumulated 161 log files in my logging directory in the past month that add up to less than 1MB. You may want to set this directory to be compressed or create a script to compress the files periodically if you tend to generate a lot of large session logs.
  7. Next you may want to click on the Terminal/Keyboard selection to display the following window. I chose to configure my PuTTY session to allow for use of the Backspace key to move the cursor backwards line it is used in a Windows command window. You will see in Figure 3 an example of that screen and how it needs to be configured to get that functionality.
    PuTTY Keyboard Options
    Figure 3
  8. The last thing you need to do before using your command line ssh (PuTTY) tool is to save the default settings. Click on the Session option on the left side of the PuTTY Configuration window as shown in Figure 1. Now click Default Settings and then the Save button. You can now close the PuTTY Configuration window using the X button in the upper right corner of the window.
  9. Now you can access network devices and servers using SSHv2 by typing ssh [IP Address] at a windows command prompt. A second window will pop up as shown in Figure 4. The second window will automatically close when you exit the SSH session based on the Always selection for the Close window on exit: settings shown in Figure 1 above.

PuTTY SSH Terminal Window - SSHv2

Figure 4
Don’t forget that you can always use your hosts file found in C:\WINDOWS\system32\drivers\etc\ for hostnames instead of typing out the IP address as shown in the above example. This is assuming you are running from a mobile environment and connecting to servers that do not have registered hostnames. The instructions and screen captures for this article were taken from PuTTY version 0.56. Please refer to the PuTTY License Page for more information on the use of the PuTTY application.You can make another copy of the executable to server a different protocol like telnet. For instance you can save a separate copy of the putty.exe as telnet32.exe in your C:\windows directory or any directory shown in your path statement when you type “set” at the command line.

4 Comments »

  1. Tech Land » Blog Archive » DHCP or Static? says

    [...] This is a fairly common question in small IT shops.  I have faced this question a couple of times in my IT career and I will share some details from my experiences.  I posted a lengthy comment on the subject of DHCP vs static IP addresses on my friend Trace’s new blog. Trace started a brand new blog a few weeks ago titled Trace Pupke:another church IT blog. Trace is the IT Director of Seacoast Church. Here is what I had to say on the question of “DHCP or Static IPs?“. I recommend that you consider DHCP reservations as a middle ground between the static addresses and your current DHCP configuration. There are several reasons for this, but the main reason is for centralized control of changes to DNS, Default Gateways, and Subnet Mask. I would definitely continue to use DHCP for laptops since they are frequently moved between your network and other networks. If you feel that static addresses are the only way for you then you might offer your users the ability to change their own IP settings on the laptops for when they travel. Here are a couple of scripts you can user in two separate BAT files to easily switch between static and DHCP without having to open the TCP/IP settings of their NIC. Put the following two lines in a file called office.bat. netsh interface ip set address name=”Local Area Connection” static 192.168.0.2 255.255.255.0 192.168.0.1 1 netsh interface ip set dns “Local Area Connection” static 4.2.2.1 primary Put these next two lines in file named away.bat. netsh interface ip set address name=”Local Area Connection” source=dhcp netsh interface ip set dns name=”Local Area Connection” source=dhcp Note: The “name” variable must match the Name shown for that NIC in the Control Panel/Network Connections. If you are wondering how I ssh from the command line of Windows you should check out my post titled SSH from Windows CMD line. [...]

    December 15th, 2006 | #

  2. Joe says

    Eh. That is pretty cool.

    I’ll probably use it… but I still wish there were a good command-line ssh tool for windows.

    August 6th, 2007 | #

  3. HOEI » Change XP IP from Command Line - money making blogs and web sites says

    [...] DHCP.  I was often running from the command line anyway to execute ping and tracert. I also use SSH from the Windows command line to access routers, switches, and firewalls so it just made sense to switch IP settings fromt he [...]

    March 23rd, 2009 | #

  4. HOEI » Change XP IP from Command Line says

    [...] DHCP.  I was often running from the command line anyway to execute ping and tracert. I also use SSH from the Windows command line to access routers, switches, and firewalls so it just made sense to switch IP settings from the [...]

    January 1st, 2010 | #

Leave a comment

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:


Subscribe without commenting

RSS feed for these comments. | TrackBack URI

Feed Icon
Subscribe to our feed.

TwitterCounter for @TheOzz

What's a feed?

Enter your email address:

Delivered by FeedBurner



Blogging Blogs - BlogCatalog Blog Directory