Skip to content

Commit 63e51df

Browse files
authored
Create keep-scripts-running-ssh.md
1 parent f5b29cc commit 63e51df

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

linux/keep-scripts-running-ssh.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Keep processes running and closing SSH connection
2+
3+
The are several alternatives. Here we cover `nohup` and `tmux`.
4+
5+
## Using `nohup`
6+
7+
```
8+
$ nohup long-running-command &
9+
```
10+
It logs `stdout` to `nohup.log`.
11+
12+
13+
## Using `tmux`
14+
15+
1) SSH into the remote machine.
16+
17+
2) Install `tmux`:
18+
```
19+
$ apt install tmux
20+
```
21+
22+
3) Start `tmux`:
23+
```
24+
$ tmux
25+
```
26+
27+
4) Start the process you want inside the started `tmux` session.
28+
29+
5) Leave/detach the `tmux` session by typing `Ctrl+b` and then `d`.
30+
31+
6) You can now safely log off from the remote machine, your process will keep running inside `tmux`.
32+
33+
7) When you come back again and want to check the status of your process you can attach to your tmux session using:
34+
```
35+
$ tmux attach
36+
```
37+
38+
If you want to have multiple sessions running side-by-side, you should name each session using `Ctrl+b` and `$`.
39+
40+
You can get a list of the currently running sessions using:
41+
```
42+
$ tmux list-sessions
43+
```
44+
or
45+
```
46+
$ tmux ls
47+
```
48+
49+
To attach to a running session with use:
50+
```
51+
$ tmux attach-session -t <session-name>
52+
```

0 commit comments

Comments
 (0)