SSH Multiplexing

Create a new file in ~/.ssh called config and insert the following:

Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

Reuse an existing SSH connection when you connect to the same host multiple times. Be sure to chmod 600 the config file.

Update: This is also nice to add (not supported on all versions of ssh client), ControlPersist 4h

SSH login using keys

Here’s how to setup SSH so you can use keys for authentication.

1. Create a set of keys:

ssh-keygen -t dsa

2. Hit “Enter” three times, we want the default location for the keys, and no passphrase.
3. You should now have a folder called .ssh in your home folder. Inside are the public and private keys.
4. Use SCP to copy the public key, “id_dsa.pub” to your remote hosts.

scp .ssh/id_dsa.pub me@10.1.2.3:

5. On each host create a .ssh folder in the account you want to access on the remote host (can be multiple accounts).

mkdir .ssh

6. Move (or copy if multiple) the id_dsa.pub file inside the .ssh folder, renaming it to authorized_keys

mv id_dsa.pub ~/.ssh/authorized_keys

7. Set the folder permissions on .ssh to 700.

chmod 700 ~/.ssh

Log out of the host and try logging back in. If everything is still set to defaults, you should be logged into the remote host without using a password.

This method is as secure as the interactive login but you need to guard your private key.

Configuring bash on a Mac

The Mac OS does not create/copy a .bash_profile for you when your account is created. Follow these steps to setup a normal bash profile.

1. Create .bash_profile with the following contents:

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

2. Create .bashrc with the following contents:

export PS1="[\u@\h:\w]\$ "

export JAVA_HOME=/Library/Java/Home

3. Add any aliases to .bashrc