-1

I have installed Visual C++ 2015 for Linux. What this does is, it takes a server name, a port number, a username, and a password, then connects to the remote machine, compiles a C++ program inside that machine, and then returns the result to my local PC.

enter image description here

Now, the problem I am facing is, I have to connect to the remote PC through a bastion-host machine.

Suppose, the IP address and port number of the bastion server are yyy.yy.y.20 and 8081 respectively; the IP address of the remote machine is xxx.xxx.x.180 but I don't know the port number.

What should be the command to create a tunnel from my local Windows 10 to the remote Linux machine?

ssh -L 22:xxx.xxx.x.180:22 yyy.yy.y.20:8081

The above command is giving me an error message:

Microsoft Windows [Version 10.0.19045.2846]
(c) Microsoft Corporation. All rights reserved.

C:\Users\pc>ssh -L 22:xxx.xxx.x.180:22 yyy.yy.y.20

C:\Users\pc>ssh -L 22:xxx.xxx.x.180:22 yyy.yy.y.20:8081
ssh: Could not resolve hostname yyy.yy.y.20:8081: No such host is known.

C:\Users\pc>

How can I setup an SSH tunnel from local Windows 10 to remote Ubuntu?

2 Answers 2

2

the openssh client does not support the hostname:port scheme. Use -p instead.

ssh -L 22:xxx.xxx.x.180:22 -p 8081 yyy.yy.y.20
11
  • Then what should I write on the VC++ Linux connection interface?
    – user366312
    Commented May 12, 2023 at 8:02
  • to connect to the tunnel? localhost? Commented May 12, 2023 at 8:03
  • what would be the port, username, and password?
    – user366312
    Commented May 12, 2023 at 8:04
  • You defined the port 22 in the -L paramater. So it seems logical to use the port 22. Commented May 12, 2023 at 8:05
  • 1
    The remote host of course. Commented May 12, 2023 at 8:09
1
+50

To create an SSH tunnel from your local Windows 10 machine to the remote Ubuntu machine through the bastion-host machine, you can use the following command:

ssh -L <local_port>:<remote_ip>:<remote_port> <bastion_username>@<bastion_ip> -p <bastion_port> -i <path_to_bastion_private_key>

In your case, the command would look something like this:

ssh -L 2222:xxx.xxx.x.180:22 [email protected] -p 8081 -i path/to/bastion/private/key

Here's what each parameter in the command means:

  • -L: Specifies the local port forwarding. In this case, we're forwarding the local port 2222 to the remote Ubuntu machine's SSH port (22).
  • <local_port>: The port number on your local machine that you want to forward traffic to. In this case, we're using 2222.
  • <remote_ip>: The IP address of the remote Ubuntu machine you want to connect to.
  • <remote_port>: The port number of the remote Ubuntu machine's SSH service.
  • <bastion_username>: The username you use to connect to the bastion-host machine.
  • <bastion_ip>: The IP address of the bastion-host machine.
  • -p: Specifies the port number to connect to on the bastion-host machine. In this case, we're using 8081.
  • -i: Specifies the path to the private key file for the bastion-host machine.

Once you run the command, you'll be prompted for the password for the bastion-host machine's username. Once you enter the correct password, the tunnel will be established and you can use your Visual C++ 2015 for Linux to connect to the remote Ubuntu machine through the tunnel using the address localhost:2222.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .