How to Share Your Linux Terminal With Other Users?


As someone who often collaborates with other users and provides remote support, we know how important it is to have efficient ways of sharing a terminal or screen with others.

Sharing your Linux terminal with other users can come in handy in several situations. For example, if you're working with a team of developers, sharing your terminal allows everyone to see and work on the same codebase simultaneously, regardless of their physical location. Similarly, if you need to provide remote support, sharing your terminal allows you to see the user's system and fix issues quickly and easily.

Remote support is another scenario where sharing your terminal can be extremely helpful. As an IT professional, you may need to troubleshoot issues for unphysically present users. By sharing your terminal with them, you can see exactly what's happening on their system and provide the necessary support quickly and effectively.

we will explore three different methods for sharing your Linux terminal or with other users using SSH, using screen, and using tmux.

Method: 1 Using SSH

SSH (Secure Shell) is a highly secure protocol that enables us to access and manage a computer over the network remotely. Its popularity lies in its speed, reliability, and most importantly, its security features. With SSH, We have the freedom to access not only the remote machine's terminal but also share our local terminal with others. We can do this by following a few simple steps which are mentioned below 

Find your machine's IP address command

ip addr

By executing this command output may look like this

1: lo: <loopback, up,="" lower_up=""> mtu 65536 qdisc no queue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope hostvalid_lft forever preferred_lft forever
2: eth0: <broadcast, multicast,="" up,="" lower_up=""> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::211:22ff:fe33:4455/64 scope link valid_lft forever preferred_lft forever

For instance, there are two network interfaces listed "lo" (the loopback interface) and "eth0" (an Ethernet interface). The output includes information about each interface's IP address (both IPv4 and IPv6), as well as its MAC address and other details.

Share your terminal with other users command

ssh -X username@your_ip_address

Output

username@your_ip_address's password:
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-91-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Wed Feb 23 14:55:36 2023 from 192.168.1.2

In the above command, replace "username" with the username of the remote user and "your_ip_address" with the IP address of your machine. The "-X" command enables X11 forwarding, which allows remote users to access graphical applications and transferring of files on their machines.

Method: 2 Using Screen

The screen is a terminal multiplexer that allows us to create multiple terminal sessions within a single terminal window. With the screen command, we can create a shared terminal session that multiple users can connect to simultaneously. There are a few commands we need to explore to connect the terminal with other users in Linux by using this "screen" method of sharing.

Start a new screen session by entering the following command

screen

The output of screen command

Welcome to screen, a window manager for terminal sessions.

Press Ctrl-A Ctrl-D to detach from the screen.
Press Ctrl-A Ctrl-D again to resume the screen session.

The "screen" command in Linux allows us to manage multiple terminal sessions within a single window using the key combination "Ctrl-A" followed by "c" to create a new session and "Ctrl-A" followed by "n" or "p" to switch between sessions. we can detach from the "screen" session by using "Ctrl-A" followed by "d" and resume it later using the "screen -r" command.

To view your current session ID, write the following command

screen -ls

The output will show all active screen sessions and session IDs.

There is a screen on
2876.pts-0.hostname	(Detached)
1 Socket in /var/run/screen/S-username.

In this above example, the session ID is "2876".

To share your screen with other users, use this command

screen -x [session ID]

The output will show an IP address of that session

screen -x 2876

When we use the "screen -x [session ID]" command in Linux, it will attach us to an existing screen session with the specified session ID. This command is useful when we have previously detached from a screen session using "Ctrl-A" followed by "d" and want to re-attach it later. You can resume your work from where you left off and even collaborate with others on the same terminal. Just make sure to specify the correct session ID if there are multiple sessions running, or we may get an error message.

Method: 3 - Using Tmux

Use the "tmux" command as an alternative to the "screen" command in Linux. Install it using the package manager and start a session with the "tmux" command. Create new windows with "Ctrl-B" followed by "c", and switch between them with "Ctrl-B" followed by "n" or "p". Detach with "Ctrl-B" followed by "d", and resume later with "tmux” attach. Tmux has additional features like window splitting and customizable interfaces.

Input command to “tmux” if it's not installed

sudo apt-get install tmux

The output will give details about tmux command

[sudo] password for user:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libevent-2.1-7 libutempter0
Suggested packages:
  ssh

The following NEW packages will be installed:
 libevent-2.1-7 libutempter0 tmux
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.Need to get 732 kB of archives.
After this operation, 2,326 kB of additional disk space will be used. Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libevent-2.1-7 amd64 2.1.8-stable-4build1 [102 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libutempter0 amd64 1.1.6-3 [7,692 B]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 tmux amd64 2.6-3 [622 kB]...
Setting up tmux (2.6-3) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

By running this command, we are able to enter the password, if it corrects then the system started downloading and installing the necessary packages for tmux. Once the installation process was complete, the output confirmed that tmux had been successfully installed in the system.

Input command to start a new tmux session

tmux new-session

Output

[exited]

When running tmux new-session in the Linux terminal, we may see [exited] indicating that a new tmux session has been created but immediately exited because no windows were added to it. To add windows to the new session, we can use the command tmux new-window.

To share the tmux session with other users, we can disable session renaming by other users and enable the Vi keybindings for the status line and copy mode. We can then detach from the tmux session by pressing Ctrl+B and then d.

Conclusion

In conclusion, sharing your Linux terminal with other users is essential for collaboration and remote access. In this article, we discussed three methods for sharing our terminal SSH, screen, and tmux. SSH provides secure access to remote systems, the screen allows sharing with multiple users simultaneously, and tmux has additional features like window splitting. As a developer or IT professional, being able to share your terminal is a valuable skill that can enhance productivity and efficiency. With the knowledge gained from this article, we can confidently collaborate with others and manage remote Linux systems easily.

Updated on: 27-Jul-2023

685 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements