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.
Related
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.
I need to connect to my university server (S) from home using my laptop (L). Since I am off campus (and my VPN does not work for some reason), I am required to first login (SSH) to my desktop (D) at the university, and then connect to S (since the server only accepts connections from computers on the campus network).
I am using Cygwin on Windows 8. I would like to know how I can create a script to auotmate this process - currently I have to manually SSH from L to D, and then again from D to S. I am new to unix.
Any help will be appreciated. Thanks.
--- Edit ---
Specifically, I would like to know how I can automate this process so that I don't have to enter my password every time.
ssh accepts a command to execute at the remote host after connecting. You can use that to launch a second ssh session:
ssh -t D ssh S
You'll be prompted for your desktop password first, then for your server password.
By the way, I recommend looking into GNU screen if you're not already using it. It prevents losing any work in case your SSH connection drops out.
To automate this even more, stick it in a bash file called "connect-university.sh":
#!/bin/bash
ssh -t D ssh S
You can then run that file from the Cygwin commandline via:
./connect-univiersity.sh
Note that the ./ part is essential, as Cygwin doesn't usually look for executable files in the current directory for security reasons.
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.
here is my problem: i would like to run a Mathematica script through ssh on a remote machine so that i can close the terminal on my computer and keep it running on the remote one.
My problem arises because the script acts in interacting mode, and so when i close the terminal the process is shut down too.
Thanks.
Use tmux or GNU screen.
Workflow:
ssh into remote machine
start tmux/screen, e.g. tmux or screen
start Mathematica script inside tmux/screen session
detach tmux/screen session, e.g. Ctrl+B d (tmux) or Ctrl+A d (screen)
close ssh connection
Then later:
ssh into remote machine
reattach to tmux/screen session, e.g. tmux attach or screen -d -R
view completed Mathematica script output
Several cases:
If you don't need to interact with it or need to visualize the notebook during evaluation
Log in to the machine with ssh
Then, to run a kernel in the background and detach it from the current session, use nohup tool (the standard output of the command will be dumped to myNotebook.out):
nohup math < myNotebook.nb > myNotebook.out &
At this point, the ssh session can be closed without killing Mathematica
Optionally you can monitor mathcommand output with the tail command (use CTRL-C to exit the tail monitoring)
tail -f myNotebook.out
If you need to see what's going on, visualize graphs during calculation or to be able to interact graphically, use remote desktop (vnc) and tunnel your communication with remote machine. Details depends a bit on the Linux distribution (vnc clients & servers may differ). You can even from Windows or Mac connect with remote desktop to your linux box and manipulate it. I suggest you to search the web for remote desktop ssh tunnel + your distro for tutorials.
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.