Change tty/pts ssh session between Unix client & server

2 min read 23-10-2024
Change tty/pts ssh session between Unix client & server

When working with Unix-based systems, especially in environments where SSH (Secure Shell) is heavily utilized, users may encounter situations where they need to switch between different TTY (teletypewriter) or PTS (pseudo-terminal slave) sessions. In this article, we'll discuss the reasons for changing TTY or PTS sessions in SSH, provide a practical example, and outline the steps to make this transition seamless.

Original Problem Scenario

The original scenario might have been presented as follows:

"Change tty/pts ssh session between Unix client & server"

Clarification

This statement suggests that you want to change the terminal type (TTY) or pseudo-terminal (PTS) session while connected to a Unix server via SSH. It indicates a need to switch or manage multiple terminal connections effectively.

Understanding TTY and PTS

What is TTY?

TTY stands for "teletypewriter" and historically referred to devices used for inputting and outputting text in a terminal. In modern Unix-like operating systems, it refers to the physical terminals connected to the system.

What is PTS?

PTS stands for "pseudo-terminal slave." It allows multiple sessions to interact with a single terminal. Each SSH connection creates a new PTS, allowing users to run separate processes or sessions independently.

How to Change TTY/Pts in an SSH Session

Here’s a step-by-step guide to effectively change or switch your TTY or PTS sessions during an SSH connection:

Step 1: Initiating an SSH Session

To start an SSH session from your Unix client to a server, use the following command in your terminal:

ssh username@server_ip_address

Replace username with your actual username and server_ip_address with the server's IP address.

Step 2: Listing Active Sessions

To see all the currently active sessions, use the who command:

who

This will display a list of users currently logged into the system along with their TTY/PTS.

Step 3: Switching Sessions

To switch to another TTY or PTS session, you can use the screen or tmux command:

  1. Using Screen:

    • Start a new screen session:
      screen
      
    • You can detach from the screen with Ctrl + A, then D to leave it running in the background.
    • To reattach, use:
      screen -r
      
  2. Using Tmux:

    • Start a new tmux session:
      tmux
      
    • Detach from the session by pressing Ctrl + B, then D.
    • To reattach, use:
      tmux attach
      

Example Scenario

Imagine you are connected to a remote server and running a long process on one terminal while needing to access another terminal for monitoring logs. Instead of opening a new SSH connection and interrupting your current session, you can simply detach from the screen or tmux session and start another session within the same SSH connection. This way, you can easily manage multiple tasks without losing progress in your existing sessions.

Conclusion

Switching between TTY and PTS sessions during an SSH session is vital for efficient workflow management on Unix-based systems. By utilizing tools like screen or tmux, you can effectively manage multiple sessions and ensure that your processes are running smoothly without interruption.

Additional Resources

By understanding the functionality of TTY and PTS, and utilizing session management tools effectively, you can enhance your productivity and streamline your Unix environment.


By following the steps outlined above, you can make the process of managing SSH sessions intuitive and efficient, catering to your specific workflow needs.