Showing posts with label Cygwin. Show all posts
Showing posts with label Cygwin. Show all posts

Thursday, April 7, 2011

Linux on Windows: CYGWIN

In order to setup a working linux environment on Windows try Cygwin. Cygwin is a implementation of a range of linux functions/functionality for Windows.

  1. Go to www.cygwin.com and download the setup file.
  2. Run the file by double click and choose "install from internet".
  3. When prompted I prefer to install Cygwin to "Program Files", which although warned about does not seem to give problems.
  4. When prompted for choosing packages choose:
    • Editors
      • emacs
      • mc
    • Net
      • openssh
      • rsync
  5. Finish the installation. 
  6. Run (double click) the shortcut on the desktop. It will create your home folder in the appropriate location (in this case (english WinXP) "C:\Program Files\cygwin\home\you").
  7. In the Cygwin window run "ssh" which will create the ".ssh" folder in your home folder.

Friday, February 11, 2011

Cygwin: Setting up a trusted ssh-relationship

If you are frequently connecting via ssh to the same server or if you are using rsync to backup your files as will be described in a later guide, you might want to set up a trusted relationship between your local computer and the remote server.

Start by generating a private/public key set.
Run the following command:
$ ssh-keygen -t rsa

Now go to your local .ssh folder.
Then download the "authorized_keys" file from the server
scp user@server.com:/home/user/.ssh/authorized_keys .
then make a backup copy of the file:
$ cp authorized_keys authorized_keys.backup
now merge public key id_rsa.pub into the authorized_keys file
$ cat authorized_keys id_rsa.pub
and upload the authorized_keys file to the server
$ scp authorized_keys user@server.com:/home/user/.ssh

Now try and connect via ssh:
$ ssh user@server.com
It should now not prompt for password.

Monday, February 7, 2011

Cygwin: Making a ssh connection with tunnels to your server

To make a ssh connection to a linux server, do the following:
Start by loading Cygwin: Start a cmd prompt and load Cygwin:
C:\folder>loadcygwin (the script is described here).

the run the ssh connect command:
C:\folder>ssh user@server.com

This will prompt for your password before allowing the connecntion. Voilá!

If you want to take advantage of one of the strengths of ssh, namely the tunnels run the command as:
C:\folder>ssh user@server.com -L 123:remotehost:456

which will open port 123 locally (on your computer/localhost) which is tunneled to port 456 on the server remotehost.

You can with benefit put this command into a batch (.cmd) file, such as the following ssh_server_com.cmd.

ssh_server_com.cmd:

@echo off
echo Connecting ...
call loadcygwin.cmd

ssh user@server.com -L1125:localhost:25 
-L22993:imap.gmail.com:993
-L993:imap.gmail.com:993 
-L22995:pop.gmail.com:995 
-L22587:smtp.gmail.com:587
-L8888:localhost:8888 
-L8080:localhost:8080

Cygwin: Setting up the environment and locale

When using Cygwin to connect to linux servers, and when using Cygwin in a windows environment in general, it is important to get the locale right.

I am using Cywin through cmd-sessions, and I load Cygwin manually for each cmd-prompt session, as I do not want to override the Windows/Dos commands by default.
Thus I run the file loadcygwin.cmd each time I want to switch to/load Cygwin.
The content of loadcygwin.cmd is listed below:

loadcygwin.cmd:

@echo off
call setcygwinenvironment.cmd
:: WinXp
set path=c:\Program Files\CygWin\bin;%path%
::Win7
::set path=C:\Program Files (x86)\cygwin\bin;%path%
echo Cygwin now loaded.

In this file I am calling the script setcygwinenvironment.cmd which sets the locale. (As you can see I am living in Denmark, which my locale settings reflect)

setcygwinenvironment.cmd:

echo Setting up CYGWIN environment...

:: Set cygwin locale to the same as windows locale.
set LANG=da_DK-UTF-8
set LC_CTYPE=da_DK.UTF-8
set LC_NUMERIC=da_DK.UTF-8
set LC_TIME=da_DK.UTF-8
set LC_COLLATE=da_DK.UTF-8
set LC_MONETARY=da_DK.UTF-8
set LC_MESSAGES=da_DK.UTF-8
set LC_ALL=da_DK
set CYGWIN=acl nodosfilewarning
echo done.

Friday, October 22, 2010

Debian NSLU2: How to install Debian on the NSLU2

Before we proceed with the installation of debian on the slug there is one point we bring in order:
We need a hard drive to install debian on.

My two slugs are installed in two different configurations:
Slug 1 (my home slug): A "WD Elements Desktop WDBAAU0010HBK 1 TB" (image) [Link 1, Link 2]

Slug 2 (my remote slug): A 4GB USB flash drive holding the operating system and a 300GB Maxtor hard drive  to hold the data.

I recommend to install the OS on a single exteramnal harddrive. And make sure you choose one which is silent and energy efficient. I can recommend the above (WD Elements Desktop WDBAAU0010HBK 1 TB), which has served me faithfully 24 hours a day, 7 days a week for a year now, but any other will do just fine.

Second thing which is important to do:
  • Connect the slug to power and your home switch and turn it on.
  • Set up the IP of the slug, the subnet mask and default gateway and the DNS server, in the native (the one the NSLU2 comes with) interface such that it is accessible from the local network and such that it has internet access. The reason for this is that the debian installation will inherit the network settings from the native setup and will use these during the setup.
  • Download and install Putty if you are running from Windows. If running from linux, just the use the built-in ssh which is sufficient.
  • A screendump of Putty connecting to the default IP address 192.168.1.77 is attached. The username is blanked out for security reasons.


  • Find and download the Debian install firmware. Doublecheck 3 times that you have the right firmware. You will find the latest Debian firmware here (on the 25th of Oct. 2010). Here I have linked to the unofficial image, which is the one I highly recommend. It is also the one I used for both of my slugs.
  • There is a great guide on how to install Debian on NSLU2 here on cyrius' page. It is the guide/page that I used myself. It is also the one containing the link to the Debian firmware.
  • Flash the slug with the downloaded firmware through the native Linksys NSLU2 interface.
  • Turn off the slug
  • Connect the harddrive.
  • Turn on/reboot the slug.
  • In Windows Connect to the slug through Putty (don't use other ways of connecting such as Cygwin, they will fail during the process). Or in Linux run the command below. In any case the username is "installer" and password is "install".
$ ssh installer@192.168.1.77 

  • Continue as described in Cyrius' guide.
  • Choose to install to entire hard drive.
  • Just use the Next, Next, Next approach whenever presented with a choice.
  • While the installer is downloading and installing the packages it would be a good time for you to think about what name your server should have. In case you want to make it available online and are sitting behind a dynamic public IP address, it would be a good time to check whether this name is available at dynamic DNS services such as dyndns.com. The thing is, that there exists a dns-updater for Debian which I use, recommend and will introduce later. Therefore I recommend dyndns.com.
    Therefore: If you want to make the server available online, go to dyndns.com, find a available hostname which suits you (but choose with care as you might get unwanted visitors if you choose a domain name which is too common - Use your common sense!).
    Create an account (might as well be with the same username as you intend to use as domain name), "buy" the domain name (for 0.00$), active it etc.
  • Let the installer finish.
  • As any guide online will tell you: "it is recommended that you install the ntpdate (or ntp) package to make sure the clock is always up-to-date. "
$ sudo apt-get update; sudo apt-get install ntpdate 
 or
    $ sudo apt-get update; sudo apt-get install ntp 

    • There, we have installed a full Debian server on your slug. You now have a full server consuming 2W+whatever your hard drive consumes. In the next few articles I will describe how to install and configure services you might need/want.