42

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.

  • 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. – davidbaumann Jun 5 '15 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 ? – Tulains Córdova Jun 5 '15 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. – davidbaumann Jun 5 '15 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. – Tulains Córdova Jun 5 '15 at 18:20
13

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.

  • The remote host is Debian and it doesn't have gnome-terminal. What is the name of the terminal app in Debian ? – Tulains Córdova Nov 27 '14 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*. – L. D. James Nov 27 '14 at 14:44
  • 1
    I tried it and it doesn't work for me. – Tulains Córdova Nov 28 '14 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? – L. D. James Nov 28 '14 at 16:27
  • The error is when executing xterm& --> [1] 26953 postgres@serverxxx:/usr/bin$ X11 connection rejected because of wrong authentication. xterm: Xt error: Can't open display: localhost:10.0 Even though I ran xhost + in the local machine. And even when I did ssh -X – Tulains Córdova Nov 28 '14 at 16:31
36

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/

  • Does "screen" need not be installed in the remote host ? – Tulains Córdova Nov 27 '14 at 14:03
  • I suppose it does. – aaditya1234 Nov 28 '14 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. – Tulains Córdova Nov 28 '14 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 – aaditya1234 Nov 29 '14 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). – ComputerScientist Aug 20 '18 at 22:46
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.

0

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

  • 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. – Marc Vanhoomissen Nov 26 '19 at 14:54
-2

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

to open new tab in terminal

or are you asking for something else?

  • 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. – Tulains Córdova Aug 13 '13 at 15:10
  • ok..got your question. will search for the answer as i dint know it yet. – aaditya1234 Aug 13 '13 at 15:18
  • Some proprietary terminals for Windows do it. But I'd preffer to use Ubuntu's terminal. – Tulains Córdova Aug 13 '13 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.