SSH Tip: Remember Last Path

ssh, Unix

Lately, I’ve been living dangerously and doing a lot of coding on the live server, via ssh. This is all proof-of-concept stuff at Ajaxify. The reason I’m coding live is that it’s all widget development and it’s just easier that way, since environments like iGoogle and Facebook need to reach my apps live, in order to test the app. None of the alternatives take my fancy: open up a port into my development PC (difficult due to dynamic DNS and less secure); upload code each change (slow even if it’s fully scripted); use Shindig on my local machine (unreliable as Shindig is new and in rapid growth mode).

So I’ve been ssh’ing and no matter how many times I’ve tried, I can’t remove ssh timeout, so I sometimes get timed out. So anyway, I wanted an easy way to remember the most recent directory I was in, each time I log back in. This is it – in my .bash_profile:

function cd { builtin cd $1 ; pwd > $HOME/.path_history; }
cd cat $HOME/.path_history

5 thoughts on SSH Tip: Remember Last Path

  1. I second Miguel’s statement about “screen”. It will change your life.

    First, imagine having several terminal sessions open in a single SSH connection that you can switch between at any time. Second, imagine getting disconnected and being able to log back in and reattach to your screen session and getting all those terminals back. Even ones with interact programs running in them (ie. vim) will be in exactly the same state as when you left.

    Cheers!

  2. Try this option to ssh:

    -o ServerAliveInterval=60

    This sends a message inside the encrypted channel every 60 seconds, keeping the connection alive to servers who may be disconnecting idle ssh sessions.

  3. Thanks guys.

    @Miguel, @David – you’re right about screen. As I think I blogged at one point, “screen” was banned at uni due so I never got into it. I know I really need to.

    @Jonathan Good tip. I’ve only tried tweaking sshd on the server. Hopefully that param will do the trick…

  4. Screen banned? Your uni must not have been teaching “how to work with unix”.

    Check out autossh + screen as well. I’ve set it up with my lappy, and as I move networks, locations, cities, my sessions are always set up just how i like them.

Leave a Reply