Making SSH Shortcuts on Mac OS X
Saving some typing
Typing ssh commands in the Terminal can get a bit tiresome if you connect to the same machine all the time. It gets downright unwieldy if you maintain multiple servers. There are some Mac programs out there that handle ssh bookmarking but they're generally not free or are inelegant.
So let's look at a way to create and organize ssh bookmarks under Mac OS X that doesn't require any third-party software. We'll use inetloc shortcuts that can be launched from the Finder or any application manager program.
What is inetloc?
Mac OS X lets you create aliases in the filesystem that point to Internet addresses. Most of the time you'll see these bundled with applications, like a file you can double-click to get to the developer's web site. These are "inetloc" files.
The nifty part about inetloc files is that they aren't restricted to just web sites. They can use any URI.
You know how a link to a website usually looks like this?
That's commonly called a URL - a Uniform Resource Locator. It's also a URI - a Uniform Resource Identifier. For our purposes the difference is that URLs point to websites or email addresses, while URIs can point to those or to other services on the Internet that have nothing to do with websites.
We're going to make an inetloc out of an ssh URI.
Constructing ssh URIs
An ssh URI looks a lot like a website URL:
You start with the connection scheme to use (ssh instead of http), then "://", then a username, "@", and the address. So the above URI would instruct a program to ssh to "www.example.com" and try to log in as user "demo".
If you run ssh on a non-standard port (usually a good idea) you can specify the port number after a colon at the end of the URI, like this:
That would ssh to www.example.com as user demo on port 30000.
Making the shortcut
With the education out of the way let's actually do something with that knowledge. Open Safari and go to the address bar.
Empty out whatever's there and enter an ssh URI. Don't hit enter yet - just type the text, like:
Now, you see that globe icon next to what you typed?
Drag that to the desktop. Just click on the globe, hold the mouse button down, drag until you're pointing to your desktop background, then let go.
On the desktop you should now see a file with a big "@" as its icon. It will be named after the connection scheme, username, and address you used.
And that's it. There's your shortcut. If you double-click it Terminal will launch and start an ssh session to your server.
Now you can do whatever you like with your shortcut. If you have several servers you ssh to regularly you can put their shortcuts together in a folder.
You can put that folder on the Dock...
...and on recent versions of Mac OS X you can click it to choose one of the shortcuts from a list.
The shortcut's just another file as far as the system is concerned. You can do anything with it you can do with a regular file, including renaming the file to something more meaningful.
Well, maybe not that meaningful.
Not just Safari
You can select a URI in a text editor and drag it to the desktop to create an inetloc as well.
If you don't want to run Safari to make the shortcut you can run TextEdit instead. Type the URI in, highlight it, then drag the URI to the desktop.
Note that when you do that you want just the URI text, not any whitespace after it (which could technically contain the invisible "new line" character, which can keep the inetloc from working).
Not just ssh
You don't need to limit your inetloc shortcuts to ssh. You can use "sftp" to start the URI if you want to save an sftp connection, for example. So long as Mac OS X knows what program can make that kind of connection you can use an inetloc shortcut for it.
sftp://email@example.com telnet://firstname.lastname@example.org ftp://email@example.com
Safari recognizes whatever URIs the Finder can handle. That means you can create bookmarks for your ssh connections inside Safari.
Safari won't let you make a bookmark like this the easy way (with a simple "Add bookmark" menu choice). You need to make an inetloc file first, then use that to add the bookmark.
Once you have the inetloc you want to bookmark open the Bookmark Manager by choosing "Show All Bookmarks" from the "Bookmarks" menu.
Once you're in the Bookmark Manager you can drag the inetloc file from the Finder to the main pane of the Bookmark Manager.
Now it's just another bookmark. You can rename it, put it in a bookmark folder, even put it on the Bookmarks Bar.
Note that when you do access a URI from Safari it will usually warn you that Safari is trying to open another application. That's a security measure. So long as you know you clicked the bookmark you can allow it to continue.
Firefox also recognizes URIs and can bookmark them. The process is the same as Safari - go to "Show All Bookmarks" in the "Bookmarks" menu, drag in the inetloc file, then organize it however you like.
It's possible to skip the inetloc step with Firefox. First click a location in the left pane of the Bookmark Manager (like the "Bookmarks Menu" or the "Bookmarks Toolbar"). With that done, look in the top panel and you'll see a menu with an icon that looks like a gear. Select that menu and choose "New Bookmark".
In the dialog box that appears you can enter a name for the bookmark, the address, and any notes you'd like.
When you try to go to that bookmark Firefox will ask you to choose the application to launch the URI. Choose "Terminal" from the list and you'll be on your way.
And there, in more detail than you probably wanted, is an approach to keeping an easily-accessed collection of shortcuts to ssh servers you commonly connect to. You can put them in a folder, you can add them to a bookmark menu, or you can add them to launcher applications like LaunchBar or Quicksilver. Anything you can use to organize files you can use to organize inetloc files.
© 2014 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
See license specifics and DISCLAIMER