Make your own free website on Tripod.com

Infrablue atTripod

 
Home
Cygwin Part 1
Cygwin Part 2
Cygwin Part 3
Int'l. Keyboard



Useful Configuration of Cygwin, Part 2: SSH and Vim



Setting up SSH

One great thing about having this setup is the ability to be able to ssh to and from remote boxes to your Windows box and to be able to transfer files with the scp command.  To do this SSH needs to be properly set up.  It is a fairly simple matter.  Just run the command
ssh-host-config from the console. 

Here is how I answer the following questions:

Should privilege separation be used? (yes/no)                    ->   No

Which value should the environment variable CYGWIN have when
sshd starts? It's recommended to set at least "ntsec" to be
able to change user context without password.
Default is "ntsec". CYGWIN=                                      ->  ntsec

Do you want to install sshd as service?
(Say "no" if it's already installed as service) (yes/no)         ->   yes

You will also be asked if you want it to generate some keys and whether you want to use them to log on.  I definitely say "no" to the RSA 1 key and say yes to both RSA and DSA 2 keys. 

Next launch start the service with the following command:

    cygrunsrv -S sshd

Now in the Services window of Administrative Tools under Control Panel you should see the
CYGWIN sshd service running.



Setting up the Vim editor

Vim (Vi IMproved) is another extremely useful and important tool that comes with Cygwin.  The long and short of getting it running properly is to set up a
.vimrc config file in your home directory.  There is already provided a good example which you can copy to your home directory:

    cp /usr/share/vim/vim63/vimrc_example.vim ~/.vimrc

The path /usr/share/vim/vimNN is dependent upon the version NN of vim installed (in this case v.6.3). 

Here is another tip: vim comes with the
view command which is an alias that opens a file in in Vim in read-only mode.  Using view you can view files with syntax-highlighting and line number display just as in vim (provided you set up your ~/.vimrc as above).



Listing package contents

If you want to know the contents of a Cygwin package use the
cygcheck command to list them.  For example:

    cygcheck.exe -l vim | less

will list the contents of the vim package.



Using sc.exe to control services remotely

Now that you have a functional shell environment and the ability to use ssh to open a remote console session one very useful command to know is
sc.exe.  Sc.exe is not part of Cygwin but rather is included with Windows XP and later.  For Windows 2000 it was included as part of a collection of command-line utilities called the Server Extensions Resource kit.  If you do not have this command on your system (hint: run which sc.exe in your BASH shell to see if/where it is) you can find places to download it.

Sc.exe allows you to query running services, search for a particular service, and to start, stop, and restart services.  Here is an example session:

$ sc query | grep -i apa
SERVICE_NAME: Apache
DISPLAY_NAME: Apache


$ sc stop Apache
SERVICE_NAME: Apache
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x4
WAIT_HINT : 0x3a98

$ sc start Apache
SERVICE_NAME: Apache
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x2
WAIT_HINT : 0xbb8
PID : 3424
FLAGS :










  Home Cygwin Part 1 Cygwin Part 2 Cygwin Part 3 Int'l. Keyboard