MacOS – How to Create SSH Connection Terminal Shortcut

macosshortcutssshterminal

It sucks to open Terminal each time and write a complete SSH command. How can I create an SSH connection Terminal shortcut on Mac OS X 10.6.8 (Snow Leopard)?

I also have a custom port to connect to.

Best Answer

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 sidney@98.256.211.12). 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

Related Question