Ubuntu – Can one access an open terminal on the computer via SSH

bashcommand linegnome-terminalssh

I'm looking to access an open terminal, that is, opened locally on my machine, from a remote computer without using tmux or screen. There's a few reasons for this, the simplest of which is that I keep landing up with a situation where I didn't plan ahead, run something big on my pc at work, go home and then want to check on it via ssh.

In essence I'm looking for a way to attach to the terminal already running on a computer and view its output.

Now, I know that there are a few threads out there that say you can't do this (such as this one ), and others that simply recommend screen and tmux (like this one, this one or this one). What I'm looking for is a way to directly access a running terminal process, or at the very least see the cached output of that terminal. I don't necessarily need to be able to enter commands in that terminal.

Is there a way to do this? Otherwise, any ideas on a hack that could work? I was thinking I could probably find a way to automatically log stdout, stderr and the commands to a file (perhaps a clever tweak on bash history that logs everything?)

Best Answer

Simply due to how terminals are built, it is not possible to access everything, i.e. you cannot view a running terminal and interact with it if you don't have a detachable session running within the said terminal, such as screen or tmux session, or if you haven't started that command with logging via script command.

What can be done is partially view TTY via sudo cat /dev/vcs1 command. /dev/vcs[1-6] correspond to their respective TTY consoles. This is limited by the scrollback buffer size of the respective TTY, which means you can only see whatever is held in memory up to certain number of lines. This of course can be tuned to increase the number of lines as shown in muru's answer here. Alternatively, you probably should try

setterm -file log.txt -dump [ttynumbers]

which was mentioned in this ssh question.

At the end of the day, bodhi.zazen properly noted in their comment, that your refusal to use screen or tmux is the biggest problem. I totally understand, I often forget to track long-running programs myself, but with some commands you should start thinking ahead.