You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/linux/connect-to-your-remote-linux-computer.md
+37-35Lines changed: 37 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
-
title: "Connect to your target Linux system in Visual Studio"
3
-
description: "How to connect to a remote Linux machine or Windows Subsystem for Linux from inside a Visual Studio C++ project."
4
-
ms.date: 03/14/2022
2
+
title: "Connect to a Target Linux System by Using Visual Studio"
3
+
description: "Learn how to connect to a remote Linux machine or Windows Subsystem for Linux from inside a Visual Studio C++ project."
4
+
ms.topic: tutorial
5
+
ms.date: 03/21/2025
5
6
---
6
-
# Connect to your target Linux system in Visual Studio
7
+
# Connect to your remote Linux system by using Visual Studio
7
8
8
9
::: moniker range="msvc-140"
9
10
@@ -26,6 +27,7 @@ You can configure a Linux project to target a remote machine or the Windows Subs
26
27
::: moniker range=">=msvc-150"
27
28
28
29
When using a remote connection, Visual Studio builds C++ Linux projects on the remote machine. It doesn't matter if it's a physical machine, a virtual machine in the cloud, or WSL.
30
+
29
31
To build the project, Visual Studio copies the source code to your remote Linux computer. Then, the code gets compiled based on Visual Studio settings.
30
32
31
33
::: moniker-end
@@ -39,7 +41,7 @@ To build the project, Visual Studio copies the source code to your remote Linux
39
41
40
42
::: moniker range=">=msvc-150"
41
43
42
-
## Set up the SSH server on the remote system
44
+
## Set up the SSH server on the remote machine
43
45
44
46
If `ssh` isn't already set up and running on your Linux system, follow these steps to install it. The examples in this article use Ubuntu 18.04 LTS with OpenSSH server version 7.6. However, the instructions should be the same for any distro using a moderately recent version of OpenSSH.
45
47
@@ -58,7 +60,7 @@ If `ssh` isn't already set up and running on your Linux system, follow these ste
58
60
59
61
## Set up the remote connection
60
62
61
-
1. In Visual Studio, choose **Tools > Options** on the menu bar to open the **Options** dialog. Then select **Cross Platform > Connection Manager** to open the Connection Manager dialog.
63
+
1. In Visual Studio on your local Windows system, choose **Tools > Options** on the menu bar to open the **Options** dialog. Then select **Cross Platform > Connection Manager** to open the Connection Manager dialog.
62
64
63
65
If you haven't set up a connection in Visual Studio before, when you build your project for the first time, Visual Studio opens the Connection Manager dialog for you.
64
66
@@ -69,11 +71,11 @@ If `ssh` isn't already set up and running on your Linux system, follow these ste
69
71
:::image-end:::
70
72
71
73
To edit an existing connection, choose **Edit**. In either scenario, the **Connect to Remote System** window is displayed.
72
-
74
+
73
75
:::image type="complex" source="media/connect-to-your-remote-linux-computer/connect-updated.png" alt-text="Screenshot of the Visual Studio Connect to Remote System window.":::
74
76
In the Connect to Remote System window, there are fields for host name, port, user name, authentication type, and password. Port is set to 22. Authentication type is set to 'Password'.
75
77
:::image-end:::
76
-
78
+
77
79
1. Enter the following information:
78
80
79
81
| Entry | Description |
@@ -84,23 +86,23 @@ If `ssh` isn't already set up and running on your Linux system, follow these ste
84
86
|**Authentication type**| Password and Private Key are both supported |
85
87
|**Password**| Password for the entered user name |
86
88
|**Private key file**| Private key file created for ssh connection |
87
-
|**Passphrase**| Passphrase used with private key selected above|
89
+
|**Passphrase**| Passphrase used with private key selected previously|
88
90
89
-
You can't click the **Connect** button until all the required fields are completed and the port is set to an integer between 1 and 65535.
91
+
You can't select the **Connect** button until all the required fields are completed and the port is set to an integer between 1 and 65535.
90
92
91
93
You can use either a password or a key file and passphrase for authentication. Key files are more secure than username/password. If you already have a key pair, it's possible to reuse it.
92
94
93
-
Versions of Visual Studio before 17.10 support Elliptic Curve (EC), Rivert-Shamir-Adleman (RSA), and Digital signature algorithm (DSA) keys for remote connections. Because of security concerns, DSA keys are no longer supported in VS 17.10 and later. RSA keys were also not supported in VS 17.10 and VS 17.11 but some types are supported again in VS 17.12 and later. To create a key pair compatible with the connection manager you can use the command:
95
+
Versions of Visual Studio before 17.10 support Elliptic Curve (EC), Rivert-Shamir-Adleman (RSA), and Digital signature algorithm (DSA) keys for remote connections. Because of security concerns, DSA keys are no longer supported in VS 17.10 and later. RSA keys were also not supported in VS 17.10 and VS 17.11 but some types are supported again in VS 17.12 and later. To create a key pair compatible with the connection manager, you can use the command:
94
96
`ssh-keygen -m pem -t ecdsa -f <key-name>`
95
97
96
98
> [!NOTE]
97
-
> If using `ssh-keygen` to create the private key, you must specify the switch `-m pem`, or the key will not be accepted by Visual Studio. If your private key begins with `-----BEGIN OPENSSH PRIVATE KEY-----`, you must convert it with `ssh-keygen -p -f <FILE> -m pem`.
99
+
> If using `ssh-keygen` to create the private key, you must specify the switch `-m pem`, or the key isn't accepted by Visual Studio. If your private key begins with `-----BEGIN OPENSSH PRIVATE KEY-----`, you must convert it with `ssh-keygen -p -f <FILE> -m pem`.
98
100
99
101
1. Choose the **Connect** button to attempt a connection to the remote computer.
100
102
101
103
If the connection succeeds, Visual Studio configures IntelliSense to use the remote headers. For more information, see [IntelliSense for headers on remote systems](configure-a-linux-project.md#remote_intellisense).
102
104
103
-
If the connection fails, an info bar with error information appears and the fields that you may need to change are outlined in red.
105
+
If the connection fails, an info bar with error information appears and the fields that you might need to change are outlined in red.
104
106
105
107
:::image type="content" source="media/connect-to-your-remote-linux-computer/settings-connection-manager-error-updated.png" alt-text="Screenshot of the Visual Studio Connect to Remote System window. The host name and port fields are outlined in red to indicate incorrect entries.":::
106
108
@@ -114,13 +116,13 @@ If `ssh` isn't already set up and running on your Linux system, follow these ste
114
116
115
117
## Host key verification
116
118
117
-
In Visual Studio version 16.10 or later, you're asked to verify the server's host key fingerprint whenever Visual Studio connects to a remote system for the first time. You may be familiar with this process if you've used the OpenSSH command-line client or PuTTY before. The fingerprint identifies the server. Visual Studio uses the fingerprint to ensure it's connecting to the intended and trusted server.
119
+
In Visual Studio version 16.10 or later, you're asked to verify the server's host key fingerprint whenever Visual Studio connects to a remote system for the first time. You might be familiar with this process if you've used the OpenSSH command-line client or PuTTY before. The fingerprint identifies the server. Visual Studio uses the fingerprint to ensure it connects to the intended and trusted server.
118
120
119
121
The first time Visual Studio establishes a new remote connection, you're asked to accept or deny the host key fingerprint presented by the server. Or, anytime there are changes to a cached fingerprint. You can also verify a fingerprint on demand: select a connection in the Connection Manager and choose **Verify**.
120
122
121
123
If you upgrade to Visual Studio 16.10 or later from an older version, it treats any existing remote connections as new connections. You're prompted to accept the host key fingerprint first. Then, Visual Studio establishes a connection and caches the accepted fingerprint.
122
124
123
-
You can also update remote connections from `ConnectionManager.exe` using the `update` argument.
125
+
You can also update remote connections from *`ConnectionManager.exe`* using the `update` argument.
124
126
125
127
## Supported SSH algorithms
126
128
@@ -137,13 +139,13 @@ Starting in Visual Studio version 16.9, support for older, insecure SSH algorith
137
139
138
140
First, a little background. You can't select the SSH algorithm to use from Visual Studio. Instead, the algorithm is determined during the initial handshake with the SSH server. Each side (client and server) provides a list of algorithms it supports, and then the first algorithm common to both is selected. The connection succeeds as long as there's at least one algorithm in common between Visual Studio and the server for encryption, HMAC, key exchange, and so on.
139
141
140
-
The Open SSH configuration file (*`sshd_config`*) doesn't configure which algorithm to use by default. The SSH server should use secure defaults when no algorithms are specified. Those defaults depend on the version and vendor of the SSH server. If Visual Studio doesn't support those defaults, you'll likely see an error like: "Could not connect to the remote system. No common client to server HMAC algorithm was found." The error may also appear if the SSH server is configured to use algorithms that Visual Studio doesn't support.
142
+
The Open SSH configuration file (*`sshd_config`*) doesn't configure which algorithm to use by default. The SSH server should use secure defaults when no algorithms are specified. Those defaults depend on the version and vendor of the SSH server. If Visual Studio doesn't support those defaults, you'll likely see an error like: *Could not connect to the remote system. No common client to server HMAC algorithm was found.* The error might also appear if the SSH server is configured to use algorithms that Visual Studio doesn't support.
141
143
142
-
The default SSH server on most modern Linux distributions should work with Visual Studio. However, you may be running an older SSH server that's configured to use older, insecure algorithms. The following example explains how to update to more secure versions.
144
+
The default SSH server on most modern Linux distributions should work with Visual Studio. However, you might be running an older SSH server that's configured to use older, insecure algorithms. The following example explains how to update to more secure versions.
143
145
144
-
In the following example, the SSH server uses the insecure `hmac-sha1` algorithm, which Visual Studio 16.9 doesn't support. If the SSH server uses OpenSSH, you can edit the `/etc/ssh/sshd_config` file as shown below to enable more secure algorithms. For other SSH servers, refer to the server's documentation for how to configure them.
146
+
In this example, the SSH server uses the insecure `hmac-sha1` algorithm, which Visual Studio 16.9 doesn't support. If the SSH server uses OpenSSH, you can edit the `/etc/ssh/sshd_config` file to enable more secure algorithms. For other SSH servers, refer to the server's documentation for how to configure them.
145
147
146
-
First, verify that the set of algorithms your server is using includes algorithms supported by Visual Studio. Run the following command on the remote machine to list the algorithms supported by the server:
148
+
First, verify that the set of algorithms your server is using includes algorithms supported by Visual Studio. Run the following command on the remote machine to list the algorithms supported by the server:
147
149
148
150
```bash
149
151
ssh -Q cipher; ssh -Q mac; ssh -Q kex; ssh -Q key
@@ -169,7 +171,7 @@ These examples can be added anywhere in `/etc/ssh/sshd_config`. Ensure that they
169
171
170
172
After editing the file, restart the SSH server (`sudo service ssh restart` on Ubuntu) and attempt to connect again from Visual Studio.
171
173
172
-
#### Cipher example
174
+
#### Cipher example
173
175
174
176
Add: `Ciphers <algorithms to enable>`
175
177
For example: `Ciphers aes128-cbc,aes256-cbc`
@@ -191,25 +193,25 @@ For example: `HostKeyAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp384`
191
193
192
194
## Logging for remote connections
193
195
194
-
You can enable logging to help troubleshoot connection problems. On the menu bar, select **Tools > Options**. In the **Options** dialog, select **Cross Platform > Logging**:
196
+
You can enable logging to help troubleshoot connection problems. On the menu bar, select **Tools > Options**. In the **Options** dialog, select **Cross Platform > Logging**:
195
197
196
-
:::image type="complex" source="media/remote-logging-vs2019.png" alt-text="Screenshot of the Visual Studio options screen.":::
197
-
The options are open to Cross Platform > Connection Manager > Logging. Enable logging is checked, log to a file is checked, the logfile directory is set the documents folder, and log to the 'Cross Platform Logging' pane in the output window is checked.
198
-
:::image-end:::
198
+
:::image type="complex" source="media/remote-logging-vs2019.png" alt-text="Screenshot of the Visual Studio options screen.":::
199
+
The options are open to Cross Platform > Connection Manager > Logging. Enable logging is checked, log to a file is checked, the logfile directory is set the documents folder, and log to the 'Cross Platform Logging' pane in the output window is checked.
200
+
:::image-end:::
199
201
200
-
Logs include connections, all commands sent to the remote machine (their text, exit code and execution time), and all output from Visual Studio to the shell. Logging works for any cross-platform CMake project or MSBuild-based Linux project in Visual Studio.
202
+
Logs include connections, all commands sent to the remote machine (their text, exit code and execution time), and all output from Visual Studio to the shell. Logging works for any cross-platform CMake project or MSBuild-based Linux project in Visual Studio.
201
203
202
-
You can configure the output to go to a file or to the **Cross Platform Logging** pane in the Output window. For MSBuild-based Linux projects, MSBuild commands sent to the remote machine aren't routed to the **Output Window** because they're emitted out-of-process. Instead, they're logged to a file, with a prefix of "msbuild_".
204
+
You can configure the output to go to a file or to the **Cross Platform Logging** pane in the Output window. For MSBuild-based Linux projects, MSBuild commands sent to the remote machine aren't routed to the **Output Window** because they're emitted out-of-process. Instead, they're logged to a file, with a prefix of `msbuild_`.
203
205
204
206
## Command-line utility for the Connection Manager
205
207
206
-
**Visual Studio 2019 version 16.5 or later**: `ConnectionManager.exe` is a command-line utility to manage remote development connections outside of Visual Studio. It's useful for tasks such as provisioning a new development machine. Or, you can use it to set up Visual Studio for continuous integration. For examples and a complete reference to the ConnectionManager command, see [ConnectionManager reference](connectionmanager-reference.md).
208
+
**Visual Studio 2019 version 16.5 or later**: *`ConnectionManager.exe`* is a command-line utility to manage remote development connections outside of Visual Studio. It's useful for tasks such as provisioning a new development machine. Or, you can use it to set up Visual Studio for continuous integration. For examples and a complete reference to the `ConnectionManager` command, see [ConnectionManager reference](connectionmanager-reference.md).
207
209
208
210
::: moniker-end
209
211
210
212
::: moniker range=">=msvc-150"
211
213
212
-
## TCP Port Forwarding
214
+
## TCP port forwarding
213
215
214
216
The `rsync` command is used by both MSBuild-based Linux projects and CMake projects to [copy headers from your remote system to Windows for use by IntelliSense](configure-a-linux-project.md#remote_intellisense). When you can't enable TCP port forwarding, disable the automatic download of remote headers. To disable it, use **Tools > Options > Cross Platform > Connection Manager > Remote Headers IntelliSense Manager**. If the remote system doesn't have TCP port forwarding enabled, this error appears when the download of remote headers for IntelliSense begins:
215
217
@@ -231,7 +233,7 @@ Visual Studio's Linux support has a dependency on TCP port forwarding. Both `rsy
231
233
232
234
::: moniker range="msvc-150"
233
235
234
-
In Visual Studio 2017, you use the same steps to connect to WSL as you use for a remote Linux machine. Use `localhost` for the **Host Name**.
236
+
In Visual Studio 2017, you use the same steps to connect to Windows Subsystem for Linux (WSL) as you use for a remote Linux machine. Use `localhost` for the **Host Name**.
235
237
236
238
::: moniker-end
237
239
@@ -247,7 +249,7 @@ sudo apt install g++ gdb make ninja-build rsync zip
247
249
248
250
### Fix WSL `localhost` connection problems
249
251
250
-
When connecting to Windows Subsystem for Linux (WSL) on `localhost`, you may run into a conflict with the Windows `ssh` client on port 22. In WSL, change the port that `ssh` expects requests from to 23 in `/etc/ssh/sshd_config`:
252
+
When connecting to WSL on `localhost`, you might run into a conflict with the Windows `ssh` client on port 22. In WSL, change the port that `ssh` expects requests from to 23 in `/etc/ssh/sshd_config`:
251
253
252
254
```bash
253
255
Port 23
@@ -270,9 +272,9 @@ To configure an MSBuild project for WSL, see [Configure a Linux project](configu
270
272
271
273
::: moniker-end
272
274
273
-
## See Also
275
+
## See also
274
276
275
-
[Configure a Linux project](configure-a-linux-project.md)\
276
-
[Configure a Linux CMake project](cmake-linux-project.md)\
277
-
[Deploy, run, and debug your Linux project](deploy-run-and-debug-your-linux-project.md)\
0 commit comments