Skip to content

Commit 10a6104

Browse files
committed
Added ability to use SSH KeyFile with or without a passphrase.
1 parent bef1d94 commit 10a6104

10 files changed

Lines changed: 97 additions & 6 deletions

File tree

docs/GeneratingKeys.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Generating an SSH Key (Windows 10)
2+
3+
## Steps
4+
5+
The following steps are options if you wish to use an SSH Private Key. These steps were written for Windows 10, however, on Linux the steps are similar.
6+
7+
1. Open PowerShell:
8+
2. **Generate key** (_with old PEM format_)
9+
1. `ssh-keygen -m PEM -t rsa -b 4096`
10+
2. In the future, we'll be able to use `ssh-keygen`.. just not yet.
11+
3. Set output name (_default is okay for basic setups_)
12+
4. Input a passphrase for the key _(OPTIONAL)_
13+
5. Windows will now generate your RSA public/private key pair.
14+
1. Default location: `%UserProfile%\.ssh` (WINOWS)
15+
2. The public key will be stored as `id_rsa.pub` in the directory
16+
6. **Upload the public key** to your remote machine
17+
1. Navigate to folder, `~/.ssh/` on Linux device
18+
2. If `~/.ssh/authorized_keys` exists, append the contents of `id_rsa.pub` to the next line.
19+
3. If it does not exist, simply upload `id_rsa.pub` and rename it to, `authorized_keys`
20+
7. Test your connection using SSH on Windows via `ssh user@hostname`
21+
22+
## Convert Key to PEM format
23+
24+
SSH.Net still has some issues with ssh-rsa. To overcome this, you'll need to convert keyfile to PEM.
25+
26+
```powershell
27+
ssh-keygen -p -P "OLD_PASSPHRASE" -N "NEW_PASSPHRASE" -m pem -f "%UserProfile%\.ssh\id_rsa"
28+
```
29+
30+
## Sample output
31+
32+
```cmd
33+
C:\workXXXXXX> ssh-keygen -m PEM -t rsa -b 4096
34+
Generating public/private rsa key pair.
35+
Enter file in which to save the key (C:\Users\XXXXX/.ssh/id_rsa):
36+
Enter passphrase (empty for no passphrase):
37+
Enter same passphrase again:
38+
Your identification has been saved in C:\Users\XXXXXX/.ssh/id_rsa.
39+
Your public key has been saved in C:\Users\XXXXX/.ssh/id_rsa.pub.
40+
The key fingerprint is:
41+
SHA256:ETNWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXcms YYYYYYY\XXXXX@ZZZZZZZZ
42+
The key's randomart image is:
43+
+---[RSA 3072]----+
44+
| oO=o |
45+
| XXXXXXXXXXXX |
46+
| XXXXXXXXXXXX |
47+
| XXXXXXXXXXXX |
48+
| XXXXXXXXXXXX |
49+
|+XXXXXXXXXXXX |
50+
|.XXXXXXXXXXXX |
51+
|oXXXXXXXXXXXX |
52+
|o+.. |
53+
+----[SHA256]-----+
54+
```
55+
56+
## Reference
57+
58+
* [https://www.onmsft.com/how-to/how-to-generate-an-ssh-key-in-windows-10]

docs/Screenshot-Cmd-GenKey.png

49.5 KB
Loading

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ This project is currently in the early alpha stages, so only Building and Deploy
3131

3232
![Tools Options](docs/ScreenShot-ToolsOptions.png)
3333

34+
### Generating Private Key (optional)
35+
36+
The following steps are options if you wish to use an SSH Private Key. These steps were written for Windows 10, however, on Linux the steps are similar.
37+
38+
1. Open PowerShell:
39+
2. **Generate key** (_with old PEM format_)
40+
1. `ssh-keygen -m PEM -t rsa -b 4096`
41+
2. In the future, we'll be able to use `ssh-keygen`.. just not yet.
42+
3. Set output name (_default is okay for basic setups_)
43+
4. Input a passphrase for the key _(OPTIONAL)_
44+
5. Windows will now generate your RSA public/private key pair.
45+
1. Default location: `%UserProfile%\.ssh` (WINOWS)
46+
2. The public key will be stored as `id_rsa.pub` in the directory
47+
6. **Upload the public key** to your remote machine
48+
1. Navigate to folder, `~/.ssh/` on Linux device
49+
2. If `~/.ssh/authorized_keys` exists, append the contents of `id_rsa.pub` to the next line.
50+
3. If it does not exist, simply upload `id_rsa.pub` and rename it to, `authorized_keys`
51+
7. DONE!
52+
3453
## Action Items
3554

3655
In order to get this project moving, the following must be done.

src/VsLinuxDebugger/Commands.Impl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private UserOptions ToUserOptions()
142142

143143
UserPrivateKeyEnabled = Settings.UserPrivateKeyEnabled,
144144
UserPrivateKeyPath = Settings.UserPrivateKeyPath,
145+
UserPrivateKeyPassword = Settings.UserPrivateKeyPassword,
145146
UserName = Settings.UserName,
146147
UserPass = Settings.UserPass,
147148
UserGroupName = Settings.UserGroupName,

src/VsLinuxDebugger/Core/SshTool.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ public void CleanDeploymentFolder(bool fullScrub = false)
6666
public bool Connect()
6767
{
6868
PrivateKeyFile keyFile = null;
69+
6970
try
7071
{
7172
if (_opts.UserPrivateKeyEnabled)
72-
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath);
73-
//// keyFile = new PrivateKeyFile(_opts.UserKeyFilePath, password);
73+
{
74+
if (string.IsNullOrEmpty(_opts.UserPrivateKeyPassword))
75+
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath);
76+
else
77+
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath, _opts.UserPrivateKeyPassword);
78+
}
79+
7480
}
7581
catch (Exception ex)
7682
{

src/VsLinuxDebugger/Core/UserOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ public class UserOptions
2323
public string UserPass { get; set; }
2424
public bool UserPrivateKeyEnabled { get; set; }
2525
public string UserPrivateKeyPath { get; set; }
26+
public string UserPrivateKeyPassword { get; set; }
2627
}
2728
}

src/VsLinuxDebugger/DebuggerPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public sealed partial class DebuggerPackage : AsyncPackage
5454
public string UserPass => _optionsPage.UserPass;
5555
public bool UserPrivateKeyEnabled => _optionsPage.UserPrivateKeyEnabled;
5656
public string UserPrivateKeyPath => _optionsPage.UserPrivateKeyPath;
57+
public string UserPrivateKeyPassword => _optionsPage.UserPrivateKeyPassword;
5758

5859
private OptionsPage _optionsPage => (OptionsPage)GetDialogPage(typeof(OptionsPage));
5960

src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class OptionsPage : DialogPage
2121

2222
[Category(Credientials)]
2323
[DisplayName("User Group Name (optional)")]
24-
[Description("Remote Machine Group Name. For RaspberryPI you may use, 'pi'.")]
24+
[Description("Remote Machine Group Name. For basic setups (i.e. RaspberryPI) it's the same as UserName.")]
2525
public string UserGroupName { get; set; } = "";
2626

2727
[Category(Credientials)]
@@ -45,5 +45,10 @@ public partial class OptionsPage : DialogPage
4545
public string UserPrivateKeyPath { get; set; } = Path.Combine(
4646
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
4747
".ssh\\id_rsa");
48+
49+
[Category(Credientials)]
50+
[DisplayName("SSH Private Key Password (optional)")]
51+
[Description("Private key password (only if it was set).")]
52+
public string UserPrivateKeyPassword { get; set; } = "";
4853
}
4954
}

src/VsLinuxDebugger/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
// You can specify all the values or you can default the Build and Revision Numbers
3030
// by using the '*' as shown below:
3131
// [assembly: AssemblyVersion("1.0.*")]
32-
[assembly: AssemblyVersion("1.3.0.0")]
33-
[assembly: AssemblyFileVersion("1.3.0.0")]
32+
[assembly: AssemblyVersion("1.6.0.0")]
33+
[assembly: AssemblyFileVersion("1.6.0.0")]

src/VsLinuxDebugger/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="VsLinuxDebugger.4d7bf4de-5015-4e24-92c0-7f9f3397b2da" Version="1.3.0" Language="en-US" Publisher="Suess Labs" />
4+
<Identity Id="VsLinuxDebugger.4d7bf4de-5015-4e24-92c0-7f9f3397b2da" Version="1.6.0" Language="en-US" Publisher="Suess Labs" />
55
<DisplayName>VS Linux Debugger</DisplayName>
66
<Description xml:space="preserve">Remotely deploy and debug your .NET apps visa SSH on your Linux device using Visual Studio 2022. Works with popular Linux distrobutions such as Ubuntu, Raspberry Pi, and more!</Description>
77
<MoreInfo>https://github.com/SuessLabs/VsLinuxDebug</MoreInfo>

0 commit comments

Comments
 (0)