Significantly speed up consequent ssh connections to the remote host
Achieve major speed up of e.g scp tab completions or other consequent connections to the same server by using ControlMaster. Append these rows into ~/.ssh/config
1 Host * 2 ControlMaster auto 3 ControlPath ~/.ssh/.sock_%r@%h:%p
SSH public key encryption - How to generate the key and how to copy it to the remote machine
1 ssh-keygen -t dsa 2 ssh-copy-id -i ~/.ssh/id_dsa.pub user@server
OS X doesn’t come equipped with ssh-copy-id but you can download the script from here.
Enable your favorite editor in production environment.
Anyone who’s ever set up or maintained a larger production environment will love this “snippet”. Production environments seldom contain your favorite editor. In fact, most times you are stuck with vi, which is fine if that happens to be your flavor. For most people vi just doesn’t fit. The only requirement for this trick is to have SSH access into the production environment.
Firstly install sshfs on your development computer.
1 sudo apt-get install sshfs
It should work for both major Debian derivates (Debian and various versions of Ubuntu). I know from experience that it works for Etch stable. If you don’t use a package manager then go to sshfs homepage and follow instructions from there.
Create a mountpoint for the production filesystem.
1 sudo mkdir -p /mnt/production-xyz/bea92
Mount it with sshfs using a syntax similar to scp.
1 sshfs marko@production_server:/opt/bea92 /mnt/production-xyz/bea92
Fire up your favorite editor and start setting up/maintaining the production environment with a smile on your face :) Once you’re done unmount it using the command below.
1 fusermount -u /mnt/production-xyz/bea92
Remote X11 apps through SSH
In order to forward X11 applications from a remote server into your local X session the server must support tunneling of X11 apps with this property in sshd_config
1 X11Forwarding yes
Then simply issue the -X parameter for the SSH client.
1 ssh -X remotehost
Now run an X11 application from the SSH terminal and it’s UI will be tunneled to your local X session.
1 gvim my_script.rb
SSH tunneling
SSH tunneling to bypass overly strict firewalls for services you need. The first port is that of the remote service, and the latter is the port you want to use on the local computer. For clarity I usually use the same port on both computers if possible. Here we initiate a tunnel into the vnc server of a remote host.
1 ssh -L 5905:localhost:5905 marko@remotehost
Next we open the vnc viewer into localhost, which in fact is the tunnel into the remote host.
1 vncviewer localhost:5