38,760
edits
(Created page with "=Multiplexeur de terminal=") |
(Updating to match new version of source page) |
||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To work on our clusters, most users will need to use [[SSH]] to connect to the cluster for job submission and monitoring, editing files and so forth. Keeping this SSH connection alive for a long period of time, ranging from hours to days, may be necessary for some users and this page proposes a variety of techniques for keeping such a terminal session alive. | |||
</div> | </div> | ||
Line 9: | Line 9: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
One simple solution is to modify the configuration of your SSH client to prolong the connection. On MacOS and Linux the client configuration is found in < | One simple solution is to modify the configuration of your SSH client to prolong the connection. On MacOS and Linux the client configuration is found in <code>$HOME/.ssh/config</code> while in Windows it is located in <code>C:\Users\<username>\.ssh\config</code>. Note that the file may not exist initially, so you will need to create it; you should add the lines | ||
</div> | </div> | ||
<source> | <source> | ||
Line 22: | Line 22: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
The programs < | The programs <code>tmux</code> and <code>screen</code> are examples of a terminal multiplexer—a program which allows you to detach your terminal session entirely, where it will keep on running on its own until you choose to reattach to it. With such a program, you can logout from the cluster, turn off the workstation or hibernate the laptop you use to connect to the cluster and when you're ready to start working again the next day, reattach to your session and start from right where you left off. | ||
{{box|'''Login Node Dependency''' | {{box|'''Login Node Dependency''' | ||
<br> | <br> | ||
Each of our clusters has several login nodes and your < | Each of our clusters has several login nodes and your <code>tmux</code> or <code>screen</code> session is specific to a login node. If you wish to reattach to a session, you must ensure you're connected to the right login node, which of course means remembering which login node you were using when you started <code>tmux</code> or <code>screen</code>. Login nodes may also occasionally be rebooted, which will kill any detached terminal sessions on that node.}} | ||
</div> | </div> | ||
Line 56: | Line 56: | ||
! Command !! Description | ! Command !! Description | ||
|- | |- | ||
| < | | <code>tmux</code> || Start a server | ||
|- | |- | ||
| < | | <code>Ctrl+B D</code> || Disconnect from server | ||
|- | |- | ||
| < | | <code>tmux a</code> || Reconnect to server | ||
|- | |- | ||
| < | | <code>Ctrl+B C</code> || Create a new window | ||
|- | |- | ||
| < | | <code>Ctrl+B N</code> || Go to next window | ||
|- | |- | ||
| < | | <code>Ctrl+B [</code> || Enable "copy" mode, allowing to scroll with the mouse and Page-Up Page-Down | ||
|- | |- | ||
| < | | <code>Esc</code> || Disable "copy" mode | ||
|} | |} | ||
</div> | </div> | ||
Line 77: | Line 77: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
If you submit a job with tmux and try to start tmux within the same job, you will get the < | If you submit a job with tmux and try to start tmux within the same job, you will get the <code>lost server</code> error message. This happens because the <code>$TMUX</code> environment variable pointing to the tmux server is propagated to the job. The value of the variable is not valid and you can reset it with: {{Command|unset TMUX}} | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
However, nested use of tmux is not recommended. To send commands to a nested tmux, one has to hit < | However, nested use of tmux is not recommended. To send commands to a nested tmux, one has to hit <code>Ctrl+B</code> twice; for example, to create a new window, one has to use <code>Ctrl+B Ctrl+B C</code>. Consider using [[#GNU Screen | screen]] inside your job (if you are using tmux on a login node). | ||
</div> | </div> | ||
Line 89: | Line 89: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
The [https://en.wikipedia.org/wiki/GNU_Screen screen] program is | The [https://en.wikipedia.org/wiki/GNU_Screen screen] program is another widely used terminal multiplexer. To create a detached terminal session, you can use the following command | ||
{{Command|screen -S <session name>}} | {{Command|screen -S <session name>}} | ||
It's a good idea to give a descriptive name to your terminal sessions, making it easier to identify them later. You can use the command < | It's a good idea to give a descriptive name to your terminal sessions, making it easier to identify them later. You can use the command <code>screen -list</code> to see a list of your detached terminal sessions on this node, | ||
{{Command | {{Command | ||
|screen -list | |screen -list | ||
Line 99: | Line 99: | ||
1 Socket in /tmp/S-stubbsda. | 1 Socket in /tmp/S-stubbsda. | ||
}} | }} | ||
You can attach to one of your sessions using the command < | You can attach to one of your sessions using the command <code>screen -d -r <session name></code>. | ||
</div> | </div> |