Subversion support and ssh key pairs

From time to time a user asks for Subversion support in TextMate, and recently I saw a comment on the Rails blog asking for it as well.

So just a note to mention that TextMate already has pretty good out-of-the-box Subversion support, and a short tutorial about how to generate ssh key pairs to avoid having to type passwords when you login over ssh.

You'll need to checkout your files from the terminal, but after that you can press ⌃⇧A to get the following menu (with Subversion actions) for the current file, or in case of Add to Repository and Commit, actions for the selected items in the project drawer.

subversion menu

Two things it currently doesn't do is:

  1. Indicate the status of a file. I plan to add the proper API so that plug-ins can provide this.

  2. Request password if you use subversion over ssh. The solution to this is to generate an ssh key pair and upload the public key to the server, so that you can connect to the server w/o having to enter password.

To generate an ssh key pair you'll need to run the following line in your terminal:

ssh-keygen -t dsa

It'll ask for location and pass phrase, and you should accept the default location (~/.ssh/id_dsa.pub) and press return when it asks for pass phrase (to give the private key a blank pass phrase).

After this you need to upload the public key to the server. For this we use scp. Substitute ceo@macromates.com with your user and server name (by default the user name is your local user):

scp ~/.ssh/id_dsa.pub ceo@macromates.com:

Finally login to the server and append the public key to authorized keys:

ssh ceo@macromates.com
mkdir .ssh          # if it's not already there
cat id_dsa.pub >>.ssh/authorized_keys
rm id_dsa.pub       # cleanup

After this, you should be able to login to the server and use scp without having to enter a password.

If you do login or copy files to your server a lot, you can setup an alias. This is done by editing ~/.ssh/config (on your local machine). For example I have this entry in that file:

Host mm
HostName macromates.com
User ceo

This defines a new host (named mm) which expands to macromates.com and with ceo as the default user. What this allows me to do is copy files like this:

scp some_image.png mm:www/images

Or

ssh mm ls www/images

The first example copies some_image.png from my local folder to the www/images folder on the server. The second example logs into the server, executes an ls www/images, and gives me back the result.

For more info about the ssh configuration file run man ssh_config.

And just for the records, my user isn't named ceo, I made that up to avoid my real user (i.e. email address) to be harvested.

34 Comments

  1. 06 Nov 2005 | # Ben Jackson wrote…

    Don't forget about the IBM keychain bash script:

    http://www.gentoo.org/proj/en/keychain/

    Super-useful in case it irritates you having to type in your keychain password every time you open a terminal.

  2. 06 Nov 2005 | # Bob Aman wrote…

    Well, it's awesome to see that those options are there, but I was thinking of something more visual, like different background colors to indicate whether the file had been changed, etc in the file browser panel. Like, if the file is out of sync, the file's row has its background color set to light red, and if it's up to date, it's colored light green. Nothing overly obtrusive — more just a gentle reminder that you're looking at files that are under source control, and so that you can see their current status at a glance.

  3. 07 Nov 2005 | # Mr eel wrote…

    I think Bob's idea is an excellent one. It's not such an issue for me at the moment since I am generally the only person working out SVN repository, but in a multi-dev environment it would be a really useful feature. A gentle reminder check in changes frequently.

  4. 07 Nov 2005 | # Allan Odgaard wrote…

    Bob, Mr eel: this is what I was addressing with item 1. The API is not there to allow it yet, so it needs to be added first, as svn support is not built into TextMate, but added through a bundle, like is also done for Darcs, SVK, Perforce etc.

    For now there's ⌃⇧A + S + return to see the status of the files in a project.

  5. 08 Nov 2005 | # Sander Cox wrote…

    For caching of SSH keys I use the SSHKeyChain http://www.sshkeychain.org/

    It work's flawless for me for a long period allready, and it can lock your keys when you put your system to sleep, very usefull with laptops.

  6. 09 Nov 2005 | # Mischa wrote…

    Hm, interesting. How about CVS is that hidden somewhere too??

  7. 10 Nov 2005 | # iznogoud wrote…

    Just a stupid question. I don't know if making ^⇧A is easy on qwerty keyboards, but on a french one, it just makes me do a

  8. 10 Nov 2005 | # Allan Odgaard wrote…

    iznogoud: the ⌃ glyph is the control modifier key.

    The subversion stuff is accessible with the mouse either clicking the gear icon in the status bar and locating Subversion or from the menu: Automation → Run Command… → Subversion

  9. 10 Nov 2005 | # iznogoud wrote…

    wouhou, that's great :) I tried almost all combinations but didn't try the ctrl key.

    that opens me quite a lot of perspectives… Thanks for that incredible text editor, since I tried it, I can't go back to my previous ones (emacs and subethaedit).

    I'll make a new suggestion on the wiki, I have a new idea:)

  10. 12 Nov 2005 | # Greg Humphreys wrote…

    Also it would be awesome if the SVN support worked with servers that use Apache 2.0 authentication as well as ssh.

  11. 12 Nov 2005 | # David wrote…

    I have Subversion installed via Fink, i.e. at /sw/bin.

    When I run the svn bundle commands, I get this error:

    Couldn't find svn
    
    If you have installed svn, then you need to either update your
    PATH or set the TM_SVN shell variable (e.g. in Preferences /
    Advanced)
    
    Locations searched:
    
    /Library/Application Support/TextMate/Support/bin/CocoaDialog.app/Contents/MacOS
    /bin
    /sbin
    /usr/bin
    /usr/sbin
    /Library/Application Support/TextMate/Support/bin
    

    How do I add /sw/bin to the path that TextMate searches? I don't want to have to set the TM_SVN variable and then repeat for all the other things that I have installed through fink.

  12. 12 Nov 2005 | # Allan Odgaard wrote…

    Put this in your ~/.bash_profile (create it, if it doesn't exist):

    export PATH="$PATH:/sw/bin"

  13. 13 Nov 2005 | # Tim Lucas wrote…

    @Greg Humphreys: just make sure you have used SVN with that repo before (for example, by doing a checkout in terminal), as SVN caches the user/pass. If it's in SVN's cache it'll work fandoodly.

  14. 03 Feb 2006 | # Ola Leifler wrote…

    Shorter version of uploading public key:

    ssh user@host 'cat >> .ssh/authorized_keys' < .ssh/id_dsa.pub

  15. 16 Feb 2006 | # jpb wrote…

    If colorized file names are going to be added, I'd like to see red for files that aren't under subversion control in a directory that has subversion controlled files, yellow for files that haven't been checked in, and green for files that haven't been modified.

  16. 18 Feb 2006 | # dreamscape wrote…

    Not sure why there is no delete command in the Subversion bundle.

    I've just duplicated the "Add to Repository", renamed it to "Delete from Repository", and in the command changed "add" to "delete" and it seems to work fine, so I'm really not sure it isn't included in the default SVN bundle… Unless you think people are just going to mad and bounce around deleting all their files, but c'mon people aren't that dumb.

  17. 26 May 2006 | # Alaskamike wrote…

    I'm a little confused about copying my key to the server. Should I use:

    scp ~/.ssh/id_dsa.pub alaskamike@macromates.com:

    and my subversion password? I am getting a "Permission denied (publickey,password)." error.

  18. 26 May 2006 | # Allan Odgaard wrote…

    You do not have any ssh account @ macromates.com — if you are thinking about the bundles repository, thus runs over webdav, not ssh.

  19. 06 Jul 2006 | # Louis Theran wrote…

    There is a reference in

    07 Nov 2005 | # Allan Odgaard wrote…

    to support for darcs, but it doesn't seem to be part of the default installation, and a google search doesn't turn anything up. Can somebody give me a pointer for TextMate darcs support? Thanks.

  20. 06 Jul 2006 | # Allan Odgaard wrote…

    Louis: It’s at the bundles repository. See Getting More Bundles for detailed instructions.

  21. 01 Aug 2006 | # Greg wrote…

    Any word on when the plug-in API mentioned in this article will be done?I agree with Bob's comment that color-coding would be very useful (or even just status characters off to the side like you see in Xcode).

  22. 03 Aug 2007 | # Jad wrote…

    Alaksamike, use ssh-copy-id -i ~/.ssh/id_dsa.pub user@host to copy your key.

  23. 20 Oct 2007 | # StuFF mc wrote…

    Insisting on Greg's comment from Aug. 2006, I was wondering if you plan a "easier/better" subversion support, something like "Versions" is about to bring, but directly in TextMate…

  24. 24 Oct 2007 | # Rich Bodo wrote…

    Thanks guys! Got it working using keychain.

    To install keychain:

    fink install keychain

    Add to ~/.bash_login:

    keychain ~/.ssh/id_rsa ~/.ssh/id_dsa . ~/.keychain/uname -a | awk {'print \$2'}-sh

    You should never have to fiddle with logins again.

    For those of you who happen to read this obscure post at the bottom of the thread, and who are looking for the one-liner to add your key to a server, you are in luck:

    $ mkdir ~/.ssh/ $ cd ~/.ssh/ $ ssh-keygen -t dsa $ cat ~/.ssh/id_dsa.pub | ssh you@example.com "cat – >> ~/.ssh/authorized_keys"

  25. 21 Nov 2007 | # diyafury wrote…

    Just a note:

    I had to set the read/write permissions on my authorized_keys file before this worked for me:

    $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys

    also, I'm a TextMate novice (have been using jEdit which has sftp support – textMate doesn't have this right?) anyway, I'm trying to checkout a remote svn project via the subversion bundle menu — svn+ssh://blah-diblah and I still get a permission denied error, my key pair has been setup and works fine from the terminal… Your post mentions something about having to checkout projects from the terminal, does this mean the menu checkout is still to be implemented or am I missing something?

  26. 21 Nov 2007 | # Allan Odgaard wrote…

    diyafury: as for authorized_keys, it needs to be so that other users cannot write to this file (or write to the .ssh directory so they can effectively replace it) since then other people can then add their public key. But it is fine that the file is world-readable (afaik).

    As for checking out repositories from TextMate, there is a checkout command, but to be honest, it has seen close to zero testing from me (though I wasn’t the one to add this command). A checkout is something you do once for a project and then never again. I did try it once or twice, and it worked, but if it doesn’t work, well, just go to Terminal and do the checkout :)

  27. 21 Nov 2007 | # diyafury wrote…

    coolio, cheers. A checkout from the terminal it is then :)

  28. 11 Jan 2008 | # Steve wrote…

    When I try to do a commit from the subversion popup page, the spinning dial starts up and never stops. After waiting a while, I killed the svn process at the command line. Once I did that, TM poped up a window asking for my SVN password.

    I have used svn at the command line for months to check in/out code and it works perfectly. My username on the svn repository is different from my username on my mac, but the first time I used svn from the command line, it failed and then I was able to put in the correct username and password. Since then (months ago), svn from the command line has worked perfectly. I think when svn is started by TM it must be using my mac user name rather than the cached name. Is there any way I can control this?

  29. 16 Jan 2008 | # Steve wrote…

    Also, I forgot to mention that after I type my comments and hit commit, in the status window the following appears:

    Authentication realm: PAC

    but I can't see any place that I can type to supply my credentials

  30. 03 Aug 2008 | # decibel.places wrote…

    This line gave me a problem – file not found

    cat id_dsa.pub >>.ssh/authorized_keys

    The previous command ssh-keygen -t dsa creates the key in the .ssh directory (with the defaults) so mkdir .ssh # if it's not already there is unnecessary and the next line should be cat .ssh/id_dsa.pub >>.ssh/authorized_keys or there should be a cd .ssh command

  31. 01 Oct 2008 | # Bill G wrote…

    I am new to TextMate. Is it possible to use the Subversion bundle with a remote server using WebDAV? I have been searching and have found no references on how to make it work. Thank you.

  32. 12 Nov 2008 | # loncho wrote…

    Hi,

    On a new project the team ask me if I can work with SVN using textmate, I was using textmate for editing code and conect ftp with cyberduck. But I not have any clue of how I have to conect textamate to a svn repository that the team sendme.

    There is a tutorial o some guidelines for a dummies ¿?.

    Thanx

  33. 05 Dec 2008 | # Abhi Beckert wrote…

    loncho: the best svn tutorial is at http://svnbook.red-bean.com/

    you don't have to read the whole thing, just the first few sections should teach you everything you need to know.

  34. 19 Aug 2009 | # Ben wrote…

    Ciaran Walsh's Project Plus plugin has support for status highlighting in many different version control systems. Very nice addition to the already awesome TM SVN support :)

    http://ciaranwal.sh/projectplus

Comments closed, you can use the mailing list for discussion.