Control Linux from Windows using Cygwin

Message boards : Number crunching : Control Linux from Windows using Cygwin

To post messages, you must log in.

AuthorMessage
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 36992 - Posted: 20 Feb 2007, 12:16:27 UTC
Last modified: 20 Feb 2007, 12:50:54 UTC

In a separate thread we discussed controlling a linux BOINC client from a windows host.

That thread also mentioned the use of VNC to control a whole Linux machine remotely.

This thread offers an alternative appraoch to remote control of a whole Linux machine, by running an X server on the windows box and connecting via Putty. Thanks to j2satx for asking the question that got be off my [lazyness] to get around to figuring out something I've been intending to do for the last couple of years.

The linux machine must already be GUI enabled. Once the installation is done and tested, to use the connection takes two single clicks, one double click, the typing of a username and password, and a single command at the Unix command line. You then get a Gnome/KDE desktop that almost fills your Windows screen.



In brief, the Five parts in the setup process are

A. Download & install Cygwin/X

B. Configure Cygwin/X

C. Download & install Putty

D. Configure Putty to run simple SSH connection

E. Reconfigure Putty and the Linux box to allow X11 forwarding

Also provided:

Part F identifies further work that might be taken on (by someone else!) to make the connection even easier.

Part G identifies how the connection is used in practice to connect to a remote machine with a Gnome desktop

Part K identifies how the connection is used in practice to connect to a remote machine with a KDE desktop

Step E20 gives tips on applying the process to other desktops such as XFCE.

The fine detail:

A. Install Cygwin tools

Cygwin is a huge project, and you certainly don't want to install the entire project. These details identify the components you need, and download and install them

A1. Visit http://cygwin.com/

A2. Right click on the link Install Cygwin now, top right of page, save to a new folder called (say) cygwin-install. Do not call it cygwin as you will need that name in a moment.

Tip: If you have more than one Windows box to install onto, put the install folder on a shared drive or inside a shared directory as all the downloaded files are saved.

A3. Run the setup.exe program you just downloaded.

Tip: later, when you install on a second machine, run this over the windows network. This allows it to find the files it saved on the first install.

A4. First setup screen, select the 'root install' directory. The Cygwin folk recommend you to use a top level windows folder for this, eg C:cygwin, D:cygwin, etc. On Vista Cygwin could have problems running from inside the Program Files folder.

Leave the other options on this screen alone.

->Next

A5. Local Package directory. Should show the location of your cygwin-install folder. If not, browse for it.

->Next

A6. Select your internet connection

If you need a proxy, set it up here, or ask setup to take the connections from IE5 (yes five- it's that old!)

->Next

A7. Download mirrors

It will take a few moments to download these, select one from the list that looks fairly close to you. The ftp mirros come at the top of the list - if you have issues downloading ftp through a firewall scroll down for the http sites towards the end.

->Next

A8. Select Packages.

If you have a single entry, 'All', click on the + to open it.

When you see a long list of items at the first directory level, scroll down to the end and click on the + next to X11.

Scroll down this list to find xorg-x11-base: Cygwin/X base. Click once on the circling arrows icon, and the word 'skip' should change to a version number (at present 6.8.99.901-1). Several other components will be selected as well, they are all needed so don't deselect anything else!

->Next

A9. Have a cup of tea while watching the progress screens go through the download, md5, install, and post-install stages. The 'total' progress bar goes from 0% to 100% several times, once for each phase.

Don't Panic when you notice that the filenames it is installing look distinctly Unix-like. They are all safely inside the Windows folder you chose, C:cygwin or whatever.

A10. Create Icons

You won't need these. I suggest you untick both check boxes - unless you want to play with other Cygwin utilities.

->Finish

B. Configure Cygwin to run X directly.

B1. Go into the new cygwin folder, copy and paste the file cygwin.bat (it may just show as cygwin if you have file extensions hidden in wondows). Rename the copy to X.bat (or just X if file extensions are hidden)

B2. Right click the new file, choose edit.

If there is not an edit option on the context menu, choose open with... and then choose notepad. DO NOT tick for 'always open with Notepad' or you will break a lot of shortcuts on your system.

B3. In the line that starts 'bash', change the -i so that the whole line now reads

bash --login -c X -multiwindow

Note that in Unix fashion, case may matter here! The X is uppercase, everything else lowercase.

B4. Save & exit the editor/notepad

B5. Test the new file by clicking or double clicking on it (depending on your windows settings). A text window appears, and shortly after a vacant X window should appear on the screen. This has a course grey background and a mouse pointer that looks like an X. You will also see an X icon in the system tray.

Tip: the title bar of the X window obeys windows mouse behaviour. Anything inside the X window obeys linux mouse behaviour.

B6. Close the X window for now using the normal windows close button.

Tip: note that you can also close the X window, including by mistake :-( if you close the text window that is associated with it


B7. Right-drag the new file to your desktop or the start button and select 'create shortcut here' in order to have a handy icon to click on to start X.

B8. (For convenience only) Right click on the new shortcut, and select Run minimised so that you don't see the cygwin window.

B9. (Cosmetic) While in the properties, change the icon for the shortcut. Click change icon, then browse. Navigate to the cygwin folder, then into the bin directory, and select the file Run. Choose one of the X icons in that file. Keep selecting OK till the property sheet closes. A few seconds later (depending on how fast your win box is) the icon will change.

Test the new icon.


C. Install Putty

C1. Go to http://www.chiark.greenend.org.uk/~sgtatham/putty/mirrors.html and click on the nearest mirror from the list. With the Putty mirros I have found the http mirros to be more reliable than ftp, and it is only a small file so it does not make a lot of difference.

C2. On the front page of the mirror, click downloads.

C3. Right click putty.exe and save target directly into the program files folder. Putty does not need any installation, the download is the program.

Tip: don't try to run Putty over your LAN. Copy the .exe across.

C4. Create a shortcut from the downloaded program to the desktop, start button, etc.

D. Create named session & test SSH command line via Putty

D1. Start Putty.

D2. You enter Putty at the Config screen. Enter the IP address or name of the target conmputer. (Names only work if you have got DNS runing locally, or have got windows networking and Samba going, or have edited the etchosts file. Each of these options is outside the scope of this tutorial).

D3. Select the SSH radio button.

D4. Enter a name for this session in the Saved Sessions box. I'm going to call it tux, after the Linux mascot.

D5. Click save.

D6. Click open

D7. You should connect to your linux box and be prompted for username & password. You will be warned that this is the first time you have connected to this remote box. Login. Type date to check that the basic login is working. Logout.

Disclaimer: if you can't part D to work, then by all means post questions here in the hope that others will answer, but it is unlikely that I will have time to do so. Some ideas to get you started are

You probably would need to be directly connected to the Linux box to sort it out. It might be worth consulting the docs for your Linux distro to find out how to enable ssh sessions. You might trh installing the ssh package, or installing sshd, and check the config files for sshd which may be at /etc/ssh/sshd_config. You might then ask on the forums for your Linux distro.

E. Configure Putty & Linux to talk using X11

E1. Open Putty again.

E2. Highlight tux in the list of saved sessions, and click load.

E3. In the left hand pane, click the + to see the contents of the connection items, and click the + to see the contents of the SSH item. Under connection/SSH is X11, click this. Tick the checkbox 'Enable X11 forwarding'

E4. Click Session in the left hand pane, click save to save the new config.

E5. Click Load.

E6. Login.

E7. Right click on the Putty title bar, or on the Putty button in the task bar. click on Event Log.

E8. In the event log, scroll down and look for a line saying Requesting X11 forwarding. If this line is missing, you didn't select or save the X11 setting at E3/E4.

E9. The next line in the event log will tell you whether the X11 connection was accepted or refused by the Linux box. If it was accepted, skip ahead to E17

E10. Assuming the X11 connection was refused (as is usual for the default settings in most distros), you now need to give yourself root or superuser privileges on the Linux box.

From most Linux installations, ie ones that have a separate root user, you'd type

su -

and then enter the root password when prompted. From a 'rootless' distro like Ubuntu you use the command 'sudo', but I am not sure of the exact syntax. Suggestions welcome.


E11. With superuser priveleges, edit the file /etc/ssh/sshd_config. Find a line like

#X11Forwarding no

which may or may not have the # at the start. Edit this line to read

X11Forwarding yes

Easy mistake: make sure you are really editing the file with the 'd' in its name. There is another file called /etc/ssh/ssh_config and editing that will not give you the success you so richly deserve!

Tip: You may prefer to use a gui editor, but some distros don't let you do superuser edits from the gui. If you are stuck with doing a command line edit, and are not familiar with Linux editors, one way is as follows:

vi /etc/ssh/sshd_config

then
-use the arrow keys to find the line,
-press i to enter insert mode,
-use the delete key to get rid of the # if any,
-arrow across to no,
-use delete or backspace to get rid of no,
-type yes,
-hit escape to leave insert mode,
-type :wq to save and exit.



E12. Restart the ssh server. On Debian you'd issue the following command while still logged in as root

/etc/init.d/ssh restart

This command is highly variable depending on the distribution. If you don't know the command, you could reboot instead.

E13. Exit from Putty if it did not die anyway in the restart.

E14. Re-start Putty.

E15. Double click on tux in the list of saved sessions.

E16. Log in as a normal user, and check the event log for X11 forwarding, as in E7-E9 above. If it is still not accepted, recheck the edit, and check that you really did restart the ssh server (on the correct machine!) and that you did exit from Putty and re-enter.

E17. Check that Linux knows about the X11 forwarding with the following command:

echo $DISPLAY

(as usual, this is case sensitive)

If all is OK there will be a machine name or an IP address followed by a colon and a decimal number, on my box I get

localhost:10.0

or you may get

127.0.0.1:10.0

Either format is fine, this means that Linux knows about its end of the X11 tunnel. A blank line is bad news. If you get this, go back and check all steps from E7 again.

If there is a machine name instead of local host, it should be the name of the linux box, not the windows one.

E18. Start X using the shortcut made in part B. Coming pack to the Putty window, type

xclock

and look at the X window. If all is well a clock will appear, showing the time provided by your linux box. Hit ctrl-C in the putty window and the clock disappears.

If you get a command not found error, skip this test, but xclock is almost always available on any X11 installation. If you get any other error, you need to do some more trouble shooting.

E19. The final test. At the unix prompt in Putty, type either

startkde

or

gnome-session

as appropriate. Note that all the kde/gnome stuff is done on the linux box, only the picture keyboard and mouse come across the network. This means you can only run a desktop environment that is already on the linux box.

E20. Background info, and running other desktops.

Normally gnome is started from gdm, which provides login features before running gnome itself. Similarly kde would normally be be run from kdm. The point here is that have to log in before running the desktop, so the usual gdm/kdm commands will not work. Instead we use the command to start a single session of the desired desktop.

If you want to run another destop using this approach, you need to find the relevant command to start a single session. If you get an error message about a 'window manager' being already open, you probably got the wrong command.

F. Further Work

Further work can be done here to make parts G and K even simpler. In my opinion the work needed would be more than the savings are worth - Ideas are as follows

F1. To enable private key files so that you don't have to log in separately - in effect this means that anyone with access to your windows username and password can also get into your unix box. If you think this is a good idea, read up about it in man ssh.

F2. To make the desktop start automatically at login. This is harder than it sounds as you need to change the way the desktop is provided for a direct connection. You'd need to disable gdm/kdm, and arrange for the connection to X to be set up when directly connected.

F3. As currently described, the linux and windows clipboards are separate. There is a cygwin application that can be loaded to merge them, but that is left as an exercise for others.

G Regular use for Gnome desktops

G1. Click on the X icon made in part B

G2. Click on the Putty icon made in part C

G3. Double click on the saved session, tux or whatever you chose to call it.

G4. Log in (if necessary)

G5. Type gnome-session at the Unix prompt

K Regular use for KDE desktops

K1. Click on the X icon made in part B

K2. Click on the Putty icon made in part C

K3. Double click on the saved session, tux or whatever you chose to call it.

K4. Log in (if necessary)

K5. Type start-kde at the Unix prompt


Hope that is useful. Feedback welcome.

River~~
ID: 36992 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37009 - Posted: 20 Feb 2007, 17:08:47 UTC

@River~~
Thx.........there is a ton of stuff here.

I'll start and see how far I get.

Appreciate all the time you spent on this effort.
ID: 37009 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 37012 - Posted: 20 Feb 2007, 17:29:54 UTC - in response to Message 36992.  
Last modified: 20 Feb 2007, 18:04:39 UTC

Replace


E4. Click Session in the left hand pane, click save to save the new config.


with:

E4. Click Session in the left hand pane, change the name in the saved sessions box (for example to tux-gui), and click save to save the new config separately from the tested one.

This way you have the option of running a session with or without X.

new step E21:

E21. At the unix prompt on your linux box, type either

cat >> ~/.bashrc
if [[ x$DISPLAY != x ]]; then startkde; exit; fi
<ctrl-D>

or

cat >> ~/.bashrc
if [[ x$DISPLAY != x ]]; then gnome-session; exit; fi
<ctrl-D>

as appropriate, or adjust as required for other desktops.

new step E22:

E22. If on connecting you now get an error message saying the access is not allowed, or some such, then you need to make .bashrc runnable with the following command

chmod 755 ~/.bashrc

exit, and try again. Once this is working you will go into the GUI or not automatically dpending on whether you ran the saved session with or without X forwarding.

Amend G3 to refer to tux-gui, not tux.

Amend title of Part G becomes to Instructions for regular use for chosen desktop.

De;ete whole of part K.

Delete F2 as resolved :-)

Insert at end

Legal Stuff

GNU FDL applies. I assert my moral right to be identified as the original author of this HowTo.

Anyone with write access to the BOINC unofficial wiki is welcome to put it on there.

R~~
ID: 37012 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 37013 - Posted: 20 Feb 2007, 17:33:56 UTC - in response to Message 37009.  

@River~~
Thx.........there is a ton of stuff here.

I'll start and see how far I get.

Appreciate all the time you spent on this effort.


Welcome. Please let me know if there is any point where the instructions take you astray. I am using you to beta test this as a how-to file for internal use on an internal site I help run.

R~~
ID: 37013 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 37020 - Posted: 20 Feb 2007, 18:41:41 UTC - in response to Message 37013.  
Last modified: 20 Feb 2007, 18:42:12 UTC

...

Also I'd be interested to know how long it takes to work through each of A, B, and E; or where you feel natural break points are if you think that any of those are too long to do at a single sitting.

I am guessing that C and D will not take you long as you already use Putty.

R~~
ID: 37020 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37024 - Posted: 20 Feb 2007, 19:34:53 UTC - in response to Message 37020.  

...

Also I'd be interested to know how long it takes to work through each of A, B, and E; or where you feel natural break points are if you think that any of those are too long to do at a single sitting.

I am guessing that C and D will not take you long as you already use Putty.

R~~


30 minutes to do A.

ID: 37024 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37026 - Posted: 20 Feb 2007, 19:43:44 UTC - in response to Message 37020.  

...

Also I'd be interested to know how long it takes to work through each of A, B, and E; or where you feel natural break points are if you think that any of those are too long to do at a single sitting.

I am guessing that C and D will not take you long as you already use Putty.

R~~


Six mins for B
ID: 37026 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37031 - Posted: 20 Feb 2007, 20:03:42 UTC - in response to Message 37020.  

...

Also I'd be interested to know how long it takes to work through each of A, B, and E; or where you feel natural break points are if you think that any of those are too long to do at a single sitting.

I am guessing that C and D will not take you long as you already use Putty.

R~~


Didn't do C and D....already working.

E took 10 mins.

Everything seemed to work correctly up to the "gnome-session" command.

I got a GUI for the Gnome, but it gave me a herd of error messages and opened Bug Buddy.

I'll have to look into the errors and see if I can find something on the Ubuntu Forums.

You did an excellent job on the directions. Only thing that didn't work according to Hoyle was the Tip after A3.......I had to run the Windows Network install or it would pop out of setup.

Let me know if you want me to do anything else.

ID: 37031 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 37032 - Posted: 20 Feb 2007, 21:21:52 UTC - in response to Message 37031.  
Last modified: 20 Feb 2007, 21:29:58 UTC

...
You did an excellent job on the directions. Only thing that didn't work according to Hoyle was the Tip after A3.......I had to run the Windows Network install or it would pop out of setup.
...


Which version of Windows are you using?

It worked for me on Win2k.

But I will amend the instructions anyway, as I want it to work for as many variations as possible.

Thanks for the user test under 'live' conditions. You took less time than I did, which means the instructions must have been reasonable, and that you have a better net connection than I have.

I get two bug reports when Gnome opens, in a window withon the Gnome desktop. Click close and they go away. No such errors on KDE.

After closing Bug Buddy, was the desktop usable and apparently complete? Or parts obviously missing? Or not there at all. See if the change to B3 in the followijg posting makes any difference (probably not, is my guess).

On both desktops there are a whole host of warning messages in the Putty window, but they do not seem to stop the connection from working. These are due to a combination of two things, slight incompatibilities between the Cygwin/X server and the Xfree86 server that the desktops are tested with, and/or a failure to test the desktops over a net connection despite the fact that any X app is defined to be workable over a network.

A3 Amend Tip

Later, when you want to install on another windows machine, copy the whole folder over the network to the new machine, not just setup.exe. This will avoid downloading the files again over the internet, tho the MD5's will be downloaded again to verify security. Make sure you choose the same mirror as the first time, or it might try to download them after all.

R~~
ID: 37032 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
Profile River~~
Avatar

Send message
Joined: 15 Dec 05
Posts: 761
Credit: 285,578
RAC: 0
Message 37033 - Posted: 20 Feb 2007, 21:26:55 UTC
Last modified: 20 Feb 2007, 21:32:56 UTC

B3. Amend

Edit the line that starts 'bash' to read

bash --login -c "X -clipboard"

Note the double quotes are necessary and the line is case sensitive.

[j2satx: You can just edit the batch file, the shortcut to it will automatically pick up the new info next time it is used, but you will have to exit from all running copies of X before the trying the new version]

With this alteration you can cut and paste from windows to Gnome/KDE and back.

F3. Delete as resolved :-)

R~~
ID: 37033 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37035 - Posted: 20 Feb 2007, 22:25:27 UTC - in response to Message 37032.  
Last modified: 20 Feb 2007, 22:30:50 UTC

...
You did an excellent job on the directions. Only thing that didn't work according to Hoyle was the Tip after A3.......I had to run the Windows Network install or it would pop out of setup.
...


Which version of Windows are you using?

It worked for me on Win2k.

But I will amend the instructions anyway, as I want it to work for as many variations as possible.

Thanks for the user test under 'live' conditions. You took less time than I did, which means the instructions must have been reasonable, and that you have a better net connection than I have.

I get two bug reports when Gnome opens, in a window withon the Gnome desktop. Click close and they go away. No such errors on KDE.

After closing Bug Buddy, was the desktop usable and apparently complete? Or parts obviously missing? Or not there at all. See if the change to B3 in the followijg posting makes any difference (probably not, is my guess).

On both desktops there are a whole host of warning messages in the Putty window, but they do not seem to stop the connection from working. These are due to a combination of two things, slight incompatibilities between the Cygwin/X server and the Xfree86 server that the desktops are tested with, and/or a failure to test the desktops over a net connection despite the fact that any X app is defined to be workable over a network.

A3 Amend Tip

Later, when you want to install on another windows machine, copy the whole folder over the network to the new machine, not just setup.exe. This will avoid downloading the files again over the internet, tho the MD5's will be downloaded again to verify security. Make sure you choose the same mirror as the first time, or it might try to download them after all.

R~~


Using W2K SP4 on the box I installed.

Good instructions (especially considering I'm a "real" UX newbie and my network connection is better than 4Mbps.

ID: 37035 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote
j2satx

Send message
Joined: 17 Sep 05
Posts: 97
Credit: 3,670,592
RAC: 0
Message 37036 - Posted: 20 Feb 2007, 22:28:34 UTC - in response to Message 37032.  

...
You did an excellent job on the directions. Only thing that didn't work according to Hoyle was the Tip after A3.......I had to run the Windows Network install or it would pop out of setup.
...


Which version of Windows are you using?

It worked for me on Win2k.

But I will amend the instructions anyway, as I want it to work for as many variations as possible.

Thanks for the user test under 'live' conditions. You took less time than I did, which means the instructions must have been reasonable, and that you have a better net connection than I have.

I get two bug reports when Gnome opens, in a window withon the Gnome desktop. Click close and they go away. No such errors on KDE.

After closing Bug Buddy, was the desktop usable and apparently complete? Or parts obviously missing? Or not there at all. See if the change to B3 in the followijg posting makes any difference (probably not, is my guess).

On both desktops there are a whole host of warning messages in the Putty window, but they do not seem to stop the connection from working. These are due to a combination of two things, slight incompatibilities between the Cygwin/X server and the Xfree86 server that the desktops are tested with, and/or a failure to test the desktops over a net connection despite the fact that any X app is defined to be workable over a network.

A3 Amend Tip

Later, when you want to install on another windows machine, copy the whole folder over the network to the new machine, not just setup.exe. This will avoid downloading the files again over the internet, tho the MD5's will be downloaded again to verify security. Make sure you choose the same mirror as the first time, or it might try to download them after all.

R~~


Actually, I didn't close Bug Buddy or get rid of the error messages in case you wanted me to try something else.

I'll go out to the computer room now and close them out and see if it is working and I just didn't know it.

ID: 37036 · Rating: 0 · rate: Rate + / Rate - Report as offensive    Reply Quote

Message boards : Number crunching : Control Linux from Windows using Cygwin



©2024 University of Washington
https://www.bakerlab.org