Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: SSH question - SSH'ing into an already open terminal on host

  1. #1
    Join Date
    Jul 2011
    Location
    South-Africa
    Beans
    678
    Distro
    Ubuntu 12.04 Precise Pangolin

    SSH question - SSH'ing into an already open terminal on host

    Hay all,

    I am able to access my ubuntu 10.04 over the internet with SSH. My question however is how can I SSH into an already open terminal.

    I want to run a script in terminal which I want to be able to access from the outside trough a SSH tunnel. This script cant be launched over the SSH as it needs to be running 24/7 and be accessable at various times (and IF possible, by different users than the one that initialized the script on the host)

    Is this possible? If so, how can I proceed in setting up something like this?

    Many thanks

  2. #2
    Join Date
    Aug 2011
    Beans
    9

    Re: SSH question - SSH'ing into an already open terminal on host

    What I do is as soon as I connect through SSH I run Screen, then I run the script or process within Screen and detatch from it using CTRL+A d

    Patrick

  3. #3
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: SSH question - SSH'ing into an already open terminal on host

    Quote Originally Posted by electriceddy View Post
    What I do is as soon as I connect through SSH I run Screen, then I run the script or process within Screen and detatch from it using CTRL+A d

    Patrick
    That's what I do as well.

    Not sure if you can access an already running terminal session.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  4. #4
    Join Date
    Apr 2006
    Beans
    24

    Re: SSH question - SSH'ing into an already open terminal on host

    It sounds like GNU screen may be what you want. You start the script in a screen session, detach and logout - at that point, it will stay running and be accessible to you if you ever re-attach to the same screen session. You can start here for more details:

    https://help.ubuntu.com/community/Screen

  5. #5
    Join Date
    Aug 2011
    Beans
    9

    Re: SSH question - SSH'ing into an already open terminal on host

    Not sure if you can either. Great thing about screen is the next time you ssh into the box you can run screen -ls get a list of all the screens and then attach using screen -r nameOfScreen.

  6. #6
    Join Date
    Dec 2008
    Beans
    2

    Re: SSH question - SSH'ing into an already open terminal on host

    Agree with above, screen is the best way I've tried so far. I've been using the same screen session since the uptime of my machine despite numerous ssh logins and accidentally closing terminal.

  7. #7
    Join Date
    Jul 2011
    Location
    South-Africa
    Beans
    678
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: SSH question - SSH'ing into an already open terminal on host

    Wow.

    Thanks for the speesy reply's.

    I got this working to a point:

    I opened up a terminal on host (A) and typed "screen"
    Then I went to the client (B) and SSH'ed into A. It worked and im logged into a blank terminal.

    When I run "screen -ls" i get:
    Code:
    There is a screen on:
    31036.pts-1.zeroburn-server  (time stamp)  (Attached) 
    1 Socket in /var/run/screen/S-zeroburn
    What is the name I need to use to attach to this screen? When I try "31036.pts-1.zeroburn-server" it gives an error. Is this because the status is "attached"?

    How can I detach on A without killing the running script?

  8. #8
    Join Date
    Jul 2011
    Location
    South-Africa
    Beans
    678
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: SSH question - SSH'ing into an already open terminal on host

    Never mind,

    I got it to detach with that ctrl + A d.

    Now the client is attached, but now the server cant view the terminal currently open. Can this be done (allowing two 'attaches' to the same terminal), even if one is only viewing and not interacting?

    SOLVED: aaaaauhm, another thing.. How do I kill the "virtual terminal" (duno what else to call it hehe). because even after closing all terminal screens on the server, the ssh'ed (client) pc still gets a terminal with "screen -ls"

    I just typed "exit".. Seemed to do the trick..
    Last edited by zero2xiii; August 18th, 2011 at 07:36 PM. Reason: Added a question

  9. #9
    Join Date
    Apr 2006
    Location
    Belgium
    Beans
    844
    Distro
    Hardy Heron (Ubuntu Development)

    Re: SSH question - SSH'ing into an already open terminal on host

    Quote Originally Posted by zero2xiii View Post
    Never mind,

    I got it to detach with that ctrl + A d.

    Now the client is attached, but now the server cant view the terminal currently open. Can this be done (allowing two 'attaches' to the same terminal), even if one is only viewing and not interacting?
    Code:
    man screen

    In short, yes it can be done. Read the screen manpage to see hos to configure IT to behave as you want IT.

    Ps. Google 'byobu', as this is ubuntu implementation of screen.

  10. #10
    Join Date
    Mar 2010
    Location
    ρθΦ=000
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: SSH question - SSH'ing into an already open terminal on host

    Quote Originally Posted by electriceddy View Post
    What I do is as soon as I connect through SSH I run Screen, then I run the script or process within Screen and detatch from it using CTRL+A d

    Patrick
    +1 for this

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •