Open another terminal window with the same SSH session as original window

171,711

Solution 1

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.

Solution 2

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/

Solution 3

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

Share:
171,711

Related videos on Youtube

Tulains Córdova
Author by

Tulains Córdova

Updated on September 18, 2022

Comments

  • Tulains Córdova
    Tulains Córdova almost 2 years

    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.

  • Tulains Córdova
    Tulains Córdova almost 11 years
    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.
  • abchk1234
    abchk1234 almost 11 years
    ok..got your question. will search for the answer as i dint know it yet.
  • Tulains Córdova
    Tulains Córdova over 9 years
    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
    Tulains Córdova over 9 years
    Does "screen" need not be installed in the remote host ?
  • Apologician
    Apologician over 9 years
    @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*.
  • abchk1234
    abchk1234 over 9 years
    I suppose it does.
  • Tulains Córdova
    Tulains Córdova over 9 years
    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
    Tulains Córdova over 9 years
    I tried it and it doesn't work for me.
  • Apologician
    Apologician over 9 years
    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?
  • Tulains Córdova
    Tulains Córdova over 9 years
    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
  • Apologician
    Apologician over 9 years
    @user1598390 You are having other issues that are separate from running an X terminal. Most likely you would get the same error if you tried to run xeyes and any other X application. You may have inadvertently deviated from the original login ID that was used to start the initial session. You can respond here or go into a chat room I setup to have extended discussion on this matter. The resolution may be to make sure you're using the same logged in ID in every case regarding this session instance. (chat.stackexchange.com/rooms/19029/expoundonanswer)
  • Tulains Córdova
    Tulains Córdova over 9 years
    I, in fact, deviated from the original login ID because the postgres user is prohibited by the administratos to open a ssh session, one has to login with a personal ID, then su into postgres. It works if don't do su - postgres. Remains to be solved how to do the trick after you su - into another user.
  • Apologician
    Apologician over 9 years
    The Stack Exchange system is advising for this to be moved into chat. They don't want the comments area to be used as a chat utility. I'll try to answer your new question by saying you may have access to the DISPLAY session if go into the new terminal before changing the userID, then running su to execute what you're trying to do.
  • abchk1234
    abchk1234 over 9 years
    Ah, here is something a friend told me about how he manages multiple machine installs: bjoernvold.com/forum/viewtopic.php?f=11&t=3228
  • YayDK
    YayDK over 6 years
    Although this technically works, it only does so if the remote server has gnome-terminal installed. Additionally, it bogs down the network. Ideally, a better solution would entail saving the connection information and starting an additional session with the same information. I have not found a solution for this yet but hope to (how I ended up here)
  • Apologician
    Apologician over 6 years
    Your question appears to be different from the user's question. I would use different ssh sessions to have two different terminals. As far as gome-terminal install, I try to gear my answer close to the user's question and the users objective. He specified gnome-terminal as part of the question (the tag part). Also, gnome-terminal is shipped as part of the Ubuntu suite. Some of the other flavors such as Lubuntu and xubuntu might not have it installed by default, but as easy, sudo apt install gnome-terminal will fix that... which the OP may have done.
  • ComputerScientist
    ComputerScientist almost 6 years
    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).
  • abchk1234
    abchk1234 over 5 years
    To scroll in screen, one needs to go in to copy mode by pressing Ctrl + A followed by [ key. cyberciti.biz/faq/… I agree its not very convenient.
  • Clyt
    Clyt about 5 years
    If you see that gnome-terminal is not installed in the server, try xterm. It should be there on all linux systems
  • Marc Vanhoomissen
    Marc Vanhoomissen over 4 years
    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.
  • Calmarius
    Calmarius about 4 years
    This will forward the image of the terminal, it doesn't open another one locally so it wasted a huge amount of bandwidth.
  • alper
    alper almost 4 years
    I get following error: libGL error: No matching fbConfigs or visuals found
  • JolonB
    JolonB almost 3 years
    gnome-terminal opens on the host desktop for me. I had to use xterm instead
  • Sekomer
    Sekomer over 2 years
    This is the only great answer in the internet. Thank you very very much.
  • Admin
    Admin about 2 years
    This is a really bad answer, just like @Calmarius points out. Downvoted since none of the X forwarding/bandwidth issue is mentioned or explained.