62

Is there a way to open a terminal window ( or tab ) with another instance of an open SSH session ?

EDIT: I have a terminal window with a remote ssh session into a server. I want to open a new tab connected to the same remote ssh session.

With File->New Tab I get another tab but I have to open another ssh session to the remote server.

4
  • If you use ssh-copy-id and a local SSH config, connecting to yourwebserver.company.net is just like 'ssh web', even no need to authenticate. Jun 5, 2015 at 16:14
  • @davidbaumann The comment is too terse. Could you elaborate it into an answer? What is 'ssh web'? How does that make possible to open a new terminal window with the same session as ? Jun 5, 2015 at 16:26
  • It's not the same session, but connecting by SSH will BR so.mich easier you won't need any other tricks. Jun 5, 2015 at 17:41
  • @davidbaumann, same session means same user (if you did su - someuser), same environment variables (if you sourced a src file), same working dir, same history, etc. Connecting without being asked for a password is nice but doesn't do all the rest. Jun 5, 2015 at 18:20

5 Answers 5

53

Perhaps this could help: screen

It is not installed by default on Ubuntu, but is provided in the repositories.

It is very useful: ssh to a remote host and type screen to enter a screen session.

Start whatever time consuming task you like, and then press Ctrl+A followed by Ctrl+C to create a new window in the screen session.

This will spawn a new shell where you can do what you want. Create even more windows using the same command.

To switch between two windows quickly, use Ctrl+A followed by Ctrl+A again. As you can see, Ctrl+A puts screen in command mode.

Ctrl+A Ctrl+D will detach from the screen session. You can then disconnect from the host and log in again later and use screen -dr to resume your session.

To go to a specific screen window, type Ctrl+A followed by a number.

Screen will exit when all active windows are closed (or the shells within have exited).

I got this from SSH and SFTP sessions.

Edit-

tmux is an alternative to screen. http://www.sitepoint.com/tmux-a-simple-start/

7
  • 1
    Does "screen" need not be installed in the remote host ? Nov 27, 2014 at 14:03
  • I suppose it does.
    – abchk1234
    Nov 28, 2014 at 14:46
  • I have to connect to many production servers: Solaris servers (new versions as well as legacy versions), Debian servers (several versions) and RedHat servers (several versions). Having to install new software in all of them is out of question. Nov 28, 2014 at 16:10
  • Ah, here is something a friend told me about how he manages multiple machine installs: bjoernvold.com/forum/viewtopic.php?f=11&t=3228
    – abchk1234
    Nov 29, 2014 at 17:08
  • 1
    When I use screen, I cannot scroll up and down, whereas I can scroll up and down in the normal command line (the one I get right after doing ssh user@machine). Aug 20, 2018 at 22:46
24

Connect to your remote server with:

ssh -X [remote-host]      

Now run:

gnome-terminal &

A terminal will appear on your local computer. From this terminal, you can run as many tabs or terminal windows as desired. They will all use the same ssh connection and be connected to the remote machine.

16
  • The remote host is Debian and it doesn't have gnome-terminal. What is the name of the terminal app in Debian ? Nov 27, 2014 at 13:49
  • 1
    @user1598390 On my installation (Version 7 - wheezy) the default terminal app is gnome-terminal. There are other terminal applications install. They are xterm, lxterm, and uxterm. I believe the most common on most distros will be xterm. You can get a list of the terminal applicatons with the commandline cd /usr/bin;ls *term*. Nov 27, 2014 at 14:44
  • 2
    I tried it and it doesn't work for me. Nov 28, 2014 at 16:14
  • What is the error message you get when you execute cd /usr/bin;ls *term*? In other words, what is the cli you executed and what was the error message? Nov 28, 2014 at 16:27
  • 3
    This will forward the image of the terminal, it doesn't open another one locally so it wasted a huge amount of bandwidth.
    – Calmarius
    Apr 2, 2020 at 14:04
2

most probably you might use OpenSSH control master multiplexing described with examples here : https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing

1
  • 1
    Welcome to AU. To be very useful, you should summarize the key points of the link you refer to. This way, even if the linked document disappears, your answer remains valid. Nov 26, 2019 at 14:54
0

I've done this before: Launch gnome-terminal on the server. ctrl+Z then bg from your original terminal window.

I normally use ssh -X -C, so you might have to do that, but I'm not sure. Also, it'll use your server's settings instead of the ones on your machine, which is sometimes inconvenient.

-4

Yeah, in the terminal (menu) click on File -> New Tab

to open new tab in terminal

or are you asking for something else?

3
  • Maybe I wasn't clear enough. I have a terminal window with a remote ssh session into another server. I want to open a new tab connected to the same remote ssh session. Look at the edit in the question. Aug 13, 2013 at 15:10
  • 1
    ok..got your question. will search for the answer as i dint know it yet.
    – abchk1234
    Aug 13, 2013 at 15:18
  • Some proprietary terminals for Windows do it. But I'd preffer to use Ubuntu's terminal. Aug 13, 2013 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .