Multiple command prompts with one SSH connection?

4

2

I have a need to do a lot in vim on a remote server which I need to SSH into. I find that it is best if I can look at multiple documents in multiple windows on my desktop, so to do this I open two or three SSH sessions to the remote server. This is getting a bit tedious though, as I have to re-enter the un/pw several times, and I have to make sure that each window remains active enough to prevent automatic log-off.

Is there a way to SSH in once and then piggy back on it with different terminal windows? (I use OSX and Ubuntu predominantly).

cwallenpoole

Posted 2011-12-10T19:45:25.670

Reputation: 742

Answers

5

Screen and tmux offer you the answers you're looking for, but to expand your question a bit, I would like to suggest you look into the matter of SSH key-based authentication so that you don't need the username and password every time you SSH into your remote server :-)

Michael Crilly

Posted 2011-12-10T19:45:25.670

Reputation: 106

Good point. It's generally more secure, too - see http://superuser.com/questions/303358/why-is-ssh-key-authentication-better-than-password-authentication

– Randy Orrison – 2011-12-11T08:08:59.553

(I actually have moved over to key-based auth) – cwallenpoole – 2014-05-29T19:09:47.773

3

One other possible alternative is using sshfs.

sshfs lets you remotely mount any directory accessible on a remote machine through ssh, as a volume on your machine. Works great. The benefit here is that you can work with all the files on the remote machine as if they are local. Overall, it will be easier to use than screen - you login once, then anything else you do with the remote files will be just as if you are working with local files.

Your other alternative is just to use vim's ability to edit remote files over ssh. See here: http://vim.wikia.com/wiki/Editing_remote_files_via_scp_in_vim

Jones

Posted 2011-12-10T19:45:25.670

Reputation: 161

2

Not exactly what you asked for, but the GNU screen utility lets you have multiple virtual terminals in a single window. It also protects against connection disruption, because you can reconnect to a disconnected screen session.

Randy Orrison

Posted 2011-12-10T19:45:25.670

Reputation: 5 749

It just might work. I'll have to try and see. – cwallenpoole – 2011-12-10T20:12:03.753

2

tmux is also an option (similar to GNU screen). It's code base is smaller and cleaner, it supports side-by-side panels without any extra messing around, and in my opinion it's a lot more pleasant to use. Screen is much more common though, so it's worth learning to use anyway.

To use tmux, just install it on the machine you want to SSH into. Then SSH in, run tmux, and you can now run multiple terminals or console apps on the same screen or in different 'windows' (analogous to Ubuntu workspaces) on the same terminal. Try man tmux for controls.

jake-low

Posted 2011-12-10T19:45:25.670

Reputation: 372

0

You can run multiple SSH sessions over a single SSH connection by making the first login (that sets up the connection) a control master and having subsequent invocations of SSH contact the control master and have their session forwarded over the master's already authenticated connection.

Do this with the following in your config file:

Host somehost
    # ~/tmp/sc must exist beforehand and should have mode 0700.
    ControlPath ~/tmp/sc/%h.%p
    ControlMaster auto

See the ssh_config(5) manpage for a few more details on exactly how this works.

cjs

Posted 2011-12-10T19:45:25.670

Reputation: 380

0

Just because no one has mentioned it yet... If your connection is fast enough, you could look at X forwarding via SSH - use the -X argument to ssh(1).

I use this on a daily basis, using MobaXterm (or in the past Xming) on a Windows PC, to access a local Linux development machine - though mainly for simple xterm windows.

Attie

Posted 2011-12-10T19:45:25.670

Reputation: 14 841

0

And another option is vim's built-in netrw plugin to open remote files. Works great with Project plugin.

But to be able to work with anything over ssh the first thing I do is to register my ssh key: ssh-copy-id user@host to register the key with the host and check ssh-agent is runing and add the key used with ssh-add.

I often do things like:

diffsplit scp://user@$REMOTE/path/to/dir/%

which diffs the file on $REMOTE host in ~user/path/to/dir with same relative name as current open file. I love vim, though I am sure it is possible in emacs too.

Martian

Posted 2011-12-10T19:45:25.670

Reputation: 749