Peter's Blog

Redefining the Impossible

Items filed under putty


Xming is an X server for Windows. With it one can run linux applications on a remote linux box with the X user interface windows appearing on ones Windows desktop:

xming demo

xming demo

Internet Explorer, xeyes and xterm in perfect harmony.

How to do this wonderous thing?

  • install xming
  • run xlaunch to fire up xming as your windows X server (should be added to quick launch), selecting the following options:
    • Multiple Windows (each app gets its own windows window)
    • Display Number 0
    • Start no Client (client is the program that runs)
    • No Access Control (I'm a trusting soul)
  • you now have an X server on your windows box as display :0. An X server is something that displays the user interface for X client programs (X keeps you on your toes by using counter-intuitive terminology).
  • open putty at the configuration of your favourite linux box.
  • enable the X forwarding option:
    X forwarding in Putty

    X forwarding in Putty

    the 127.0.0.1:0 means remote X clients will display on your new windows X server (:0) running on your pc (127.0.0.1)
  • open the ssh connection in putty and enter a command such as xterm. Amazingly, an xterm window should open on your local pc! It's wonderous, xterm is running on the remote pc but the user interface is on your windows box.

Interestingly, the ssh session you open has a DISPLAY environment variable open that tells the X clients you launch from it where to stick their displays.

peter@server:~$ echo $DISPLAY
localhost:10.0
peter@server:~$

Through the miracle of ssh this is routed back to xming on the Windows box.

Now, how about if beyond your gateway ssh server is another ssh server and you want to run your X client applications on that? The answer is amazingly simple. Open the session on the gateway server as described above and then use the command:

ssh -X name-of-other-server

you now have a command prompt on the remote remote server and if you now run

xterm

then again you get a xterm display coming up on your local windows pc but this time from the remote^2 box.

UPDATE: troubleshooting

  • may need this in /etc/ssh/sshd_config
    X11UseLocalhost yes
    
  • may need to
    sudo apt-get install xauth
    
    I needed this on a previously x-less box where I had installed gitk to do some git study on a headless server box

Filed under: putty ssh x xming


I found one advantage of using ssh (e.g. putty) over vnc: no error bells. I was using a terminal under vnc and the bells were driving me mad. I disabled them in vim with:

:set visualbell t_vb=

but still got them on the bash command line. Tried various things from google to disable them at the linux end but nothing worked. Tried disabling the sounds in vnc (Control Panel/Sounds, VNC = None) but not joy.

Don't especially want to unplug the speaker so I went with the flow and used ssh.

Sudden thought: maybe I WAS going mad?


Filed under: putty ssh ubuntu vnc

5 Comments

Uploading images to this blog can be kinda fiddly. Say I have an image in the windows clipboard (e.g. a screen clip from OneNote and I want it on the blog, I have to fire up a graphics program, paste it in, save it to a file, fire up filezilla, upload it, delete the image file.

This little script does all this for me. It asks for a file name, writes the image in the clipboard to the file, uploads it and deletes the image. Job Done.

The uploading is done using pscp, a version of scp from the putty camp. It uses my putty private key so I don't have to give a password for access to the server (I didn't use the cygwin version of ssh as it didn't like having 'c:\' in file names). The script uses the Python Imaging Library to do the grabbing and wxPython to ask for the file name.

   1  #
   2  # Upload image in clipboard to server
   3  #
   4  import wx
   5  import ImageGrab
   6  import Image
   7  import os
   8  import tempfile
   9  
  10  class MyApp(wx.App):
  11      def OnInit(self):
  12          oImage = ImageGrab.grabclipboard()
  13  
  14          if not isinstance( oImage, Image.Image):
  15              #
  16              # In no way is wxPython an easy to use library.
  17              #
  18              dlg = wx.MessageDialog( None, 'No image in clipboard', 'Error', wx.OK)
  19              dlg.ShowModal()
  20              dlg.Destroy()
  21              return True
  22  
  23          dlg = wx.TextEntryDialog( None, 'Enter a file name', 'Upload Clipboard', '')
  24          if dlg.ShowModal() != wx.ID_OK:
  25              dlg.Destroy()
  26              return True
  27  
  28          strName = dlg.GetValue()
  29          dlg.Destroy()
  30  
  31          strTempFile = tempfile.mktemp( strName)
  32          oImage.save( open( strTempFile, 'wb'))
  33  
  34          strCmd = 'pscp -q -i "c:\my documents\puttykey.ppk" %s me@myserver.com:www/images/%s' % (strTempFile, strName)
  35  
  36          os.system( strCmd)
  37  
  38          os.unlink( strTempFile)
  39  
  40          return True
  41  
  42  app = MyApp(0)
  43  app.MainLoop()
Toggle Line Numbers

This is the result of alt-print screen and running this script:

images/grab.jpg

The script itself inside VIM

ToDo:

  • handle file names in clipboard
  • detect upload errors
  • allow resizing images

4 Comments

Putty is a simply great ssh client and works nicely with open-ssh, which is found in Ubuntu Linux, Site5 and just about everywhere.

A nice feature of ssh is the ability to generate a public key that can be used to log into a server without having to give a password, or as extra secutiry in addition to the password.

Here is a procedure for creating ssh keys that can be used in both open-ssh and putty:

  • On windows, install the open-ssh package with Cygwin
  • execute the command
    ssh-keygen -t ssh-dss
    
    to generate the dss key. You may need to create the directory ~/.ssh in Cygwin bash for this to work. This will create a file in this directory called id_dsa.pub
  • use sftp/ssh to copy the id_dsa.pub file to your ssh server box. Put the contents of this file (which is one big long line) at the end of a file called ~/.ssh/authorised_keys2, adding it to any other keys that are already there.
  • back on windows, execute the command 'puttygen', from the putty site.
  • In putty gen, use file/load private key to load in the file ~/.ssh/id_dsa
  • Choose 'save private key' and store it somewhere handy where putty can find it. You may be prompted to enter a passphrase. This is a password used in addition to the key when connecting to the server. If the passphrase is blank then you don't have to enter it, the connection will be automatic.
  • Open putty and enter the details of the server you want to connect to (address etc)
  • In the 'connection' settings, enter your login name in 'Auto-login username'.
  • In Connection/SSH/Auth, in the box 'Private key file for authentication' load the putty private key file.
  • Save this configuration so you don't have to do it again.
  • Click 'open'

Your life won't be the same again.


2 Comments

Got the key-based login to ssh working. The steps to do this are:

  • use puttygen to genera SSH 2 RSA keys.

  • Copy the public key to a text file and copy it to the ~/.ssh/authorised_users file on the server

  • Save the private key file

  • Configure putty to read the private key file when it connects

Login asks for a user name but then goes smoothly in.


Filed under: putty ssh

3 Comments

Managed to access home router setup page using port forwarding in ssh. Used putty, added a tunnel with these settings:

  • Remote

  • Source Port: 5080

  • Destination: 192.168.0.1:80

Then connected mozilla to http://127.0.0.1:5080/.


Filed under: putty ssh


Discovered rsync and unison which are tools for syncing files and directories. unison appears to have better windows support via gtk (which makes it look like a naff tk app). It syncs locally ok and could be a nice way to do nightly backups. To do remote backups requires it to be set up to fork a ssh command. Unfortunately it does not provide good hooks for doing this in the setup file: trying to use plink (a command line version of putty) I get this:

 Received unexpected header from the server:  expected "U" but received "\013". This is probably because you have different versions of Unison installed on the client and server machines. 

Both appear to be version 2.9.1, the difference appears to be a windows/unix line delimiter problem. Plink has no options to fiddle with this. I might be able to fix it with Cygwin but that is becoming like installing linux on top of windows (I just wanna run ssh without installing 20M of unix environment).

What I really want is an ftp based solution as that would let be publish websites.


2 Comments

I tried the dpkg-reconfigure thing and got network going on old laptop nicely. Putty connects to it nicely, apache running.

Router set up, I'll try it from work tomorow.


Filed under: apache putty


WOL didn't work sad

I've been reading about using SSH for port forwarding. This may be an option but I don't know if the SSH port is blocked by the firewall here at work.

I've looked at PuTTY which seems like a nice GUI for SSH but I don't know of a public SSH server to try to connect to.


Filed under: putty ssh