Posted in CVS at 六月 25th, 2010 / No Comments »

CVS over SSH without a password


How to use CVS from home
Note: in the following I have talked about CygWin. The same applies to Linux too. It will enable you to access the Station’s files (and even login) in a secure and encrypted fashion without a password!!

How to install CVS access via SSH (do this only once)
Install CygWin, with the openssh package and the cvs package

Start CygWin or a Linux terminal

You need to prepare the remote host first so login to it using ssh. This is also a good test because if this doesn’t work then nothing else will. You will be prompted for your password.

   ssh username@hostname   (eg. ssh nk@cvs.sat.dundee.ac.uk)
Then create the ssh directory:

   mkdir -p ~/.ssh
Take a note of whether you already have the file ~/.ssh/authorized_keys2

Back in CygWin run this command to generate your keys. You will be prompted to enter a key password.

   ssh-keygen -t rsa
If you have no authorized_keys2 file on the remote host then in CygWin run:

   scp ~/.ssh/id_rsa.pub user@hostname:~/.ssh/authorized_keys2
The scp command will ask you for the password on the remote host. If you already had the file then just append the data from the CygWin file onto the end of the file already on the remote host, rather than using the above command which would overwrite it. The required information will be a line of gibberish followed by user@local.host.name.

How to enable CVS access via SSH (do this each time you start CygWin)
Start CygWin

Run this command to start a password server:

   eval `ssh-agent`
Note the backward quotes. You can put this in your .bash_profile file so that it happens automatically every time you start CygWin.

Enter your password for this session using:

You could put this command in your .bashrc too. However, if you use Linux and start X-Windows automatically then it won’t be able to prompt you for the password. In that case, on the KDE Desktop, open the .kde/Autostart folder and Create New…|Link to Application… and add ssh-add as the command, making sure you tick Run In Terminal.

How to setup CVS locally (do this only once)
The first thing you need to do is download an initial copy of the software and setup the CVS directories. Then in future you can simply update those files when the CVS repository changes.

Note: you need to run these commands in CygWin but the files can be stored anywhere on your local drive for access by the normal Windows/DOS programs. So if you store your programs in J:\programs then in CygWin you should first change into that directory:

   cd J:\programs
Tell CVS how you will be accessing the repository. You need to specify that ssh will be used, give your username and the remote hostname, and specify the path to the repository on the CVS server. These commands can be placed in your .bash_profile:

   export CVS_RSH=/usr/bin/ssh
   export CVSROOT=:ext:user@hostname:/users/local/swdev/cvs
Now checkout some software. If the ssh-add command worked then these cvs commands will not prompt you for a password. Otherwise you will need to enter a password every time!

   cvs checkout utils
   cvs checkout programs/tracking/predict
How to use CVS over SSH
Assuming everything has been setup as above, simply update your local files with new versions from the repository. You can do this in each directory as required, or you can do it in your root directory (of your local CVS tree) if you have the patience to wait whilst everything is updated.

   cvs update
The output will be a single-letter code for each filename:

U = updated OK.
P = updated OK using a patch.
M = your local copy has been modified with respect to the repository and the changes have not yet been committed, OR
M = as above but changes from the repository were successfully applied
C = a conflict occurred between your local copy and that in the repository. (Your local file has been “broken” by having the repository’s changes applied so you will need to edit it).
? = local file is not in repository (for example executables need not be committed to the repository).
A = local file is new and has been “added” to the repository but the addition has not yet been committed (you need to “commit” all changes you make, even additions or removals).
R = ditto but local file removed.
OK, now we have up-to-date files we can edit them (ALWAYS update your local copy before editing!).

To submit your changes back to the repository you may wish to follow this procedure: produce a “diff” to find out exactly what changes you are making, the use “commit” when you are happy and want to commit them. The commit process will prompt you to enter a message describing the changes you have made. This should be something more meaningful than simply “Updated”, “Fixed” or similar!

   cvs diff predict.c
   cvs commit predict.c
   cvs commit -m “Fixed default baud at 115200″ predict.c
You can give multiple filenames to each command if the same message applies to all of them. WARNING: if you omit the filename then the command will apply to ALL changed files. Not often what you intended!

More details (adding/removing files, adding new directory trees, etc.) upon request.


Published in CVS

No Responses to “SSH下设置CVS不用密码”

Leave a Reply