Original link: https://v2fy.com/p/2023-09-30-16-23-38-tmux/
When writing a program, you need to temporarily put the secret key token into the environment variable. However, if you close the window, the session will be lost and the secret key token information will be destroyed. Some programs need to be debugged on the server side and check real-time logs. If the remote working network is unstable and SSH is disconnected, after reconnecting and logging in, if you want to continue debugging, you have to restart the program. If you are frequently disconnected, your blood pressure will really soar. In order to solve the above problems, we can use Tmux for session management, thereby solving the problem of session information being lost after ssh is disconnected. For example, not using Tmux is equivalent to playing stand-alone games at home. If there is a power outage at home, the unsaved game progress will be lost; using Tmux is equivalent to playing stand-alone games with a cloud host. Even if there is a power outage at home, the cloud host will still keep you. game progress, you can continue playing when you reconnect. Install Tmux on the server side. The client does not need to install Tmux. Tmux is a server-side software. apt install tmux Tmux open source address https://ift.tt/AJYV7ge How to use the core function of Tmux Tmux is a session (session) management tool. If we want to use Tmux, we must create a session. Each session can correspond to multiple windows ( window), each window can correspond to multiple panes. Pane is an enhanced function, which is equivalent to opening several windows of the same session. We will not talk about it in this issue. Create session # After creating a session, the session number will be given at the bottom. The first default number is 0 tmux new We can open another terminal, log in to the server, and run tmux ls to see the currently available sessions. The newly opened window You can also use session number 0 # Add a new window to session number 0 tmux attach -t 0 Then the interesting thing comes, since the two windows share the same session, enter the command in the first window, and enter the command in the second window. It will also be displayed synchronously, which means that tmux running on the server is helping us manage the session status. User input and server input can be seen in real time by users joining the same session. If we want to exit the current session without destroying the session, just run detach. If we want to exit and destroy the current session, just run exit. If the program is running and detach cannot be entered, we can press Ctrl-b in tmux and then press d. If we want to end the session named 0 after exiting tmux, we can run tmux kill-session -t 0 directly in the terminal. The above is the core function of Tmux. We can create a session on the server to help us even after disconnecting from the network. It can save the Token in the environment variable and ensure that the log of the debugger is continuously printed. If you don’t need to deal with the server, installing and running Tmux on your local machine can also prevent you from closing a window during the development process, causing the program that has been running for a long time to be interrupted. Summary Tmux is a good tool for working with weak network. If you are often troubled by SSH disconnection and loss of progress, or your hands shake to close the local terminal window, you might as well try Tmux. A good tool can cultivate a good mentality. The permanent update address of this article: https://ift.tt/YG1DZj4
This article is reproduced from: https://v2fy.com/p/2023-09-30-16-23-38-tmux/
This site is for inclusion only, and the copyright belongs to the original author.