Close ssh session without logging out at the remote computer - ssh

I am currently implementing a web server on a raspberry py using the web.py framework. For convenience, I am using ssh, so I can perform tests on the raspberry directly from my laptop.
My problem is that I can't close the ssh session without the web server stopping to work, because when the session closes, a logout is performed automatically.
Does anyone know a possibility to avoid the logout while closing the ssh session? I am using Linux on both my laptop and the raspberry. Thank you.

The best way to do this is by using screen. It lets you "multiplex" your command line, meaning you can run multiple commands at the same time. Also, when you exit your ssh session, the commands running in screen will continue to run, and it is very easy to install as well.
Here's a guide for installing and running it, and if you have any other questions, comment or google for more screen guides
Edit in 2022: These days many people prefer tmux to screen. My personal recommendation would be tmux, but both do the trick!

I have raspLite on the raspberry pi 3 model b and this is how i used screen in the bash enviroment.
ssh pi#hostname
apt-get install screen
screen
Then I press Enter to proceed through the License Agreement.
npm start
Then I close the terminal and the webserver continues untill i use the SIGINT kill command on the pid.

Related

Pycharm cannot finish updating skeletons

I'm newly moving from a Linux working environment to Windows, and I'm mainly using local port forwarding+Pycharm to run my python code on a server that is double-hop from my laptop.
I am able to establish the ssh tunnel through Windows cmd or MobaXterm local terminal or MobaXterm tunneling tool. I works fine on my Pycharm, when I check it from tools/deployment/configuration/test connection, and I can also see the files in remote server. But every time I start my Pycharm, it shows two background process, "updating python interpreter" and "updating pycharm helper", and the precess bar simply do not show any moving on! And I cannot run python on remote server, because Pycharm says I lack python helper.
And most wired, when it is running these two precess, my terminal for local port forwarding freezes, and I cannot type in commands in the jump server. And when I try to recheck the connection, it turns out that connection fails.
My ssh tunneling+pycharm deployment used to work fine in my Ubuntu. Thanks anybody who can shed light on my confusion!
Well, thanks everyone, I have solved this problem.
The reason is simple, but I did not notice that the ~/.pycharm_helper 's size is actually changing in the process, while the GUI bar may be not moving.
So it is due to my double-hop inconvenience, and the low Internet speed. I left it in dorm for a whole night out, and it comes out just fine.

Google Compute Engine instance restarts when I ssh

I have a deep learning vm setup on google cloud platform. I ssh into by clicking the ssh button in my list of vm instances. The problem I am having is that if I run a program and close the ssh window while it is still running, when I ssh back into the vm, the program has been interrupted and the whole vm essentially has restarted.
Is there a way to setup my vm so that I can run a program and then close the ssh connection without it restarting the vm? I want to be able to run programs without being required to leave the ssh window open and my computer on.
As #Rup pointed out, processes belonging to your SSH session's shell will get a hang-up signal when you close the connection. To bypass the hang-up signal and let a program continue running, use the nohup command. Here is an example
nohup python test.py &
That will run the program test.py and as well as ignore the hang-up signal. The programs output will be stored in a nohup.out file.

SSH from one computer, continue on another?

I have a home server running Ubuntu Server 14.04 and I've setup OpenSSH on it. But. I'm intending to run some terminal based stuff that takes long time to be finished.
So what I wanna be able to do is ssh into the server, start the process, log out of the computer i connected with and connect from another device and have that process I started still running.
Almost like a remote-desktop type SSH connection.
If this is not possible then I'll just install a desktop environment and vnc server.
Try nohup & command.
This way the shell should keep the process running, even if you log out.
One option is the program tmux or screen, which you can detach from and log out.
Instructions for tmux:
$ ssh me#server
$ tmux
run commands
Ctrl-B d (this
means push CTRL-B then push d to detach from tmux) logout
If you want to see the results, use tmux attach when you log back in. Your session will be exactly as you left it.

run gnu-screen/tmux/byobu from client

I need to understand a fundamental concept about terminal multiplexers yet I can't seem to find the answer.
As I understand these programs need to be installed on server but not necessarily on clients. It's not a problem with gnu-screen as it is already installed on most systems but it's not the case for tmux and byobu. The problem is that I don't have permission to install software on the server. Is there a way I can run byobu from my client to show statistics about the server I connect?
Also what exactly is the effect of 'byobu-enable' option?
I think there is a misunderstanding here. When you connect to the server and run a command (byobu in this case), you are running the command on the server. Statistics reported are for the server. It's possible to open a byobu session on your own desktop of course, but if you're ssh'd into a machine, you're very likely to be executing commands on that machine.
byobu-enable sets byobu to launch automatically when you open a terminal. I don't do this since you can have confusion if you have byobu running locally and on the remote end you have connected to, which causes problems when you try to interact with byobu itself.

How to run a CPU Hogging Program on Remote Server?

I am about to run a machine learning program which might take a day or two to complete; I do not want to run it on my laptop, but on a remote server. Now I am thinking if I ssh into the machine and run the program there, and close the ssh session, how will I know next time I ssh into the machine if the program is still running or completed?
Use screen instead. Assuming you have it installed, just run screen from the ssh session. You will be given a new shell.
Once you start the program you can detach the session from your terminal by typing ^a d (CTRL+a followed by d).
Later, when you ssh back in, run screen -r to reattach the session to your current terminal.
(Note that just plain killing off the ssh session will in fact also detach the screen session, not kill it.)
man screen for further reading. screen is very powerful, and learning the ^a action sequences would be well worth your time. I use screen daily and love it.