So... You have some sweet python code that takes 2 days to run. Madmax5 is feeling lonely and you figure you'd just run your sweet.py there. Easy, right:
~$ ssh tommy@madmax5 tommy@madmax5:~$ python2.7 sweet.py Starting sweet pie... 1 minutes... 2 minutes... ^Z [1]+ Stopped python2.7 sweet.py tommy@madmax5:~$ bg 1 [1]+ python2.7 sweet.py & tommy@madmax5:~$ exit Connection to madmax5 closed.
This should be all good when you log back in to madmax5, right? Not really... Even if the job survives you can't really re-attach it so there's no easy way to see what the job is up to<<Footnote(Not to mention that the sweet process has no parent now and might eventually just get killed.)>>. That's where screen & tmux come in. What?! Think of the two as virtual terminals... You know how you can have multiple tabs open in some applications? Think of screen & tmux as tabs for your ssh session. Here's a quick session:
~$ ssh tommy@madmax5 # Let's start a screen session (open a new tabbed thingie) tommy@madmax5:~$ screen -s myScreen # Run something in the first tab tommy@madmax5:~$ uptime 14:20:32 up 145 days, 8:48, 10 users, load average: 33.03, 33.07, 33.08 # Create a new tab by pressing Ctrl+A, C (C is for create... and also for cookie) tommy@madmax5:~$ python2.7 sweet.py Starting sweet pie... 1 minutes... 2 minutes... # Switch between the tabs by pressing Ctrl+A, N (for next) or Ctrl+A, P (for previous) or Ctrl+A, " (that brings up a list) # Want to "minimize" screen and come back later? Press Ctrl+A, D (to detach)
Great, now we have tabs. What's so good about them? They stay open even after you log out. How do you get back to them?
~$ ssh tommy@madmax5 # Bring back the session we detached tommy@madmax5:~$ screen -x myScreen ... 10 minutes... 11 minutes... 12 minutes... 13 minutes... 14 minutes... 15 minutes...
I lost my permissions when when I re-attached !@#$@#$&^!$!$!!
It has to do with Kerberos... and since somebody else already wrote a guide on it, here's a link: ScreenKerberos. Same thing applies to tmux.