SSH (Secure Shell) is a powerful tool that allows users to securely access remote servers and execute commands. One of the useful features of SSH is X11 forwarding, which enables users to run graphical applications on a remote server and display them on their local machine. However, in some cases, you may need to perform multi-hopping, where you connect to one server and then connect from there to another server. In this article, we will explore how to set up X11 forwarding after multi-hopping in SSH.
Before we dive into the details, let's briefly explain the concept of X11 forwarding. X11 is a protocol that allows graphical user interfaces (GUIs) to be displayed on a remote machine. X11 forwarding allows you to run GUI applications on a remote server and have them displayed on your local machine. This can be especially useful when working with applications that have a graphical interface or when you need to visualize data.
To get started with X11 forwarding after multi-hopping, you will need two SSH clients: one for the initial connection and another for the subsequent connection. Let's assume you have two servers: Server A and Server B. You want to connect to Server A first and then from there, connect to Server B and enable X11 forwarding.
Here are the steps to set up X11 forwarding after multi-hopping in SSH:
- Open a terminal or command prompt on your local machine.
- Connect to Server A using SSH:
ssh username@serverA
Replace username with your actual username and serverA with the hostname or IP address of Server A. Enter your password when prompted.
- Once connected to Server A, initiate a new SSH connection to Server B:
ssh -X username@serverB
Again, replace username with your actual username and serverB with the hostname or IP address of Server B. Enter your password when prompted.
Now that you are connected to Server B, X11 forwarding needs to be enabled. To do this, follow these steps:
- Edit the SSH configuration file on Server B:
sudo nano /etc/ssh/sshd_config
This command opens the SSH configuration file in the nano text editor with root privileges.
- Locate the line that says
#X11Forwarding noand change it toX11Forwarding yes. - Save the changes and exit the text editor. In nano, you can do this by pressing
Ctrl+Oand thenCtrl+X. - Restart the SSH service on Server B for the changes to take effect:
sudo service ssh restart
X11 forwarding is now enabled on Server B. You can proceed to run graphical applications and have them displayed on your local machine.
To test X11 forwarding, you can run a simple graphical application like xeyes. Just type xeyes into the terminal and hit enter. If everything is set up correctly, you should see a pair of eyes displayed on your local machine.
That's it! You have successfully set up X11 forwarding after multi-hopping in SSH. Now you can run any graphical application on Server B and have it displayed on your local machine.
Remember to close the SSH connections when you are finished. Simply type exit in the terminal to disconnect from Server B, and then again to disconnect from Server A.
References
| Number | Source |
|---|---|
| 1 | https://www.ssh.com/ssh/tunneling/example |
| 2 | https://www.ssh.com/ssh/config |
| 3 | https://www.cyberciti.biz/faq/how-to-install-and-configure-openssh-server-in-ubuntu-18-04/ |