ssh: Remember each host’s settings

ssh: Remember each host’s settings

When you start using ssh to connect to other linux-based computers, you’re probably only going to a handful of machines. Easy enough to remember the username and hostname, but this won’t do when you’re working on 5 or more servers, especially if some offer ssh on a non-default port.

~/.ssh/config

In this file, you can set all the options for each host, including the username, host or ip, port, even which key to use. Here’s an example:

#Contents of $HOME/.ssh/config
Host dev
HostName 192.168.0.1
User dev-deploy
Port 2222
IdentityFile ~/.ssh/id_rsa.deploy.key

Host prod
HostName www.example.com
User prod555deploy
Port 5899

Host www.example.com
User admin123
Port 5899

It’s that easy! To use this config information, simply ssh:

ssh prod

Happy Computing!

X11 Forwarding

A few days, I moved my desktop computer out into the living room. The computer has a tuner card that can receive digital broadcasts. I don’t own a TV, so this is the closest I’ve got to one. I still have to set up lircd before I can use a remote, but I wanted something a bit easier

Today, I discovered a new trick … SSH X11 Forwarding. Now, I can play video on my desktop right from my netbook. It’s wonderful and very simple!

In the following instructions, the “A” refers to the computer playing the video and “B” refers to any other computer.

  1. Make sure “X11Forwarding Yes” is in your sshd_config file on computer A. Restart sshd if you had to uncomment/add it.
  2. On B, run `ssh -XC A`
  3. In the ssh session, type `DISPLAY=:0.0`.
  4. Now run mplayer or any other video player in the  ssh session and it will play on computer A.

If you want  to have a program run on computer A and use the screen on computer B, the process is very similar:

  1. Make sure “X11Forwarding Yes” is in your sshd_config file on computer A. Restart sshd if you had to uncomment/add it.
  2. On B, run `xhost A`
  3. On B, run `ssh -XC A`
  4. Now run mplayer or any other video player in the  ssh session and it will play on computer A.

Step 2 authorizes use of the current display by computer A and only needs to be run once. Also, note that the display variable doesn’t need to be set when using B‘s screen.

Mplayer works wonderfully when playing on my desktop, plus I control it via the ssh session. It has tons of keyboard shortcuts. The ones I use the most are space for pause and the arrow keys for skipping around.