How to create an ssh connection Terminal shortcut on Mac OS X?

The most *NIX-y answer is to use SSH's features to your advantage.

Create a file named config in ~/.ssh/ (a folder named .ssh in your home folder). Add an entry for each computer you want to connect to, like this:

Host compy
    HostName 98.256.211.12
    Port 90
    User sidney
    IdentityFile ~/.ssh/my_rsa_key
  • HostName can be either an IP address or an actual hostname.
  • Port is not mandatory if using default SSH port
  • IdentityFile is not mandatory if not using a key.

    Then, to connect, just type

ssh compy

If you use key-based authentication and store your key's password in the Keychain, you won't even need to enter a password.

In addition, you can create a .command file (a plain text file with the extension .command) containing the command line you use to connect to the server (ssh compy or ssh -i ~/.ssh/my_rsa_key -p 90 [email protected]). It will open in Terminal and run that command.

You can also use the New Remote Connection… menu item in Terminal to connect. Just add your host under SSH by clicking the + button in the right column.

Read more HERE


You have a couple of options that I can think of:

Create a .command file

In your favorite text editor create to save a plain text file with your ssh command, eg.

ssh -p 23 [email protected]

Name the file WHATEVERYOUWANT.command. You then need to set the .command file with execute privileges (chmod 755 /PATH/TO/WHATEVERYOUWANT.command) but you now have a file that when double-clicked will open up Terminal and run that command.

Create aliases for your shell

Assuming you're using bash (the default shell in Mac OS X) you can add aliases to your .bashrc in your home folder.

eg. alias sshserver='ssh -p 23 [email protected]'

You can find more about aliases at [Wikipedia](http://en.wikipedia.org/wiki/Alias_(command) or by reading the documentation.


There are many ways to do this. Here is what I do:

Open Terminal Preferences

Duplicate your profile on the Settings tab with the gear icon. This changes your default setting file, so change your old default back to what it was before the duplication.

In your new custom settings click on Shell type in your ssh command in the Run Command at Startup section.

Rename your new setting from Custom to whatever you want.

You can now start your session from the New Window or New Tab menu items, and of course a keyboard shortcut can be assigned in Keyboard & Mouse in System Preferences.


For those who use a private key with their ssh and want to use the ~/.ssh/config method you can add an 'IdentityFile' attribute to your host followed with the key path. I.e:

Host SomeServer
    User ubuntu
    HostName someserver.com
    IdentityFile ~/.ssh/private.key

I would've added this bit as a comment to one of the answers, but my reputation is still low and I'm not allowed to do so.


You can create an AppleScript that will run a command for you:

tell application "Terminal"
    do script "ssh server.example.com"
end tell