Skip to content

Commit

Permalink
Merge pull request #16 from SuessLabs/feature/keygen
Browse files Browse the repository at this point in the history
Added Key File feature with optional passphrase
  • Loading branch information
DamianSuess authored Apr 1, 2022
2 parents bef1d94 + 10a6104 commit e74355d
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 6 deletions.
58 changes: 58 additions & 0 deletions docs/GeneratingKeys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generating an SSH Key (Windows 10)

## Steps

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.

1. Open PowerShell:
2. **Generate key** (_with old PEM format_)
1. `ssh-keygen -m PEM -t rsa -b 4096`
2. In the future, we'll be able to use `ssh-keygen`.. just not yet.
3. Set output name (_default is okay for basic setups_)
4. Input a passphrase for the key _(OPTIONAL)_
5. Windows will now generate your RSA public/private key pair.
1. Default location: `%UserProfile%\.ssh` (WINOWS)
2. The public key will be stored as `id_rsa.pub` in the directory
6. **Upload the public key** to your remote machine
1. Navigate to folder, `~/.ssh/` on Linux device
2. If `~/.ssh/authorized_keys` exists, append the contents of `id_rsa.pub` to the next line.
3. If it does not exist, simply upload `id_rsa.pub` and rename it to, `authorized_keys`
7. Test your connection using SSH on Windows via `ssh user@hostname`

## Convert Key to PEM format

SSH.Net still has some issues with ssh-rsa. To overcome this, you'll need to convert keyfile to PEM.

```powershell
ssh-keygen -p -P "OLD_PASSPHRASE" -N "NEW_PASSPHRASE" -m pem -f "%UserProfile%\.ssh\id_rsa"
```

## Sample output

```cmd
C:\workXXXXXX> ssh-keygen -m PEM -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\XXXXX/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\XXXXXX/.ssh/id_rsa.
Your public key has been saved in C:\Users\XXXXX/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ETNWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXcms YYYYYYY\XXXXX@ZZZZZZZZ
The key's randomart image is:
+---[RSA 3072]----+
| oO=o |
| XXXXXXXXXXXX |
| XXXXXXXXXXXX |
| XXXXXXXXXXXX |
| XXXXXXXXXXXX |
|+XXXXXXXXXXXX |
|.XXXXXXXXXXXX |
|oXXXXXXXXXXXX |
|o+.. |
+----[SHA256]-----+
```

## Reference

* [https://www.onmsft.com/how-to/how-to-generate-an-ssh-key-in-windows-10]
Binary file added docs/Screenshot-Cmd-GenKey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ This project is currently in the early alpha stages, so only Building and Deploy

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

### Generating Private Key (optional)

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.

1. Open PowerShell:
2. **Generate key** (_with old PEM format_)
1. `ssh-keygen -m PEM -t rsa -b 4096`
2. In the future, we'll be able to use `ssh-keygen`.. just not yet.
3. Set output name (_default is okay for basic setups_)
4. Input a passphrase for the key _(OPTIONAL)_
5. Windows will now generate your RSA public/private key pair.
1. Default location: `%UserProfile%\.ssh` (WINOWS)
2. The public key will be stored as `id_rsa.pub` in the directory
6. **Upload the public key** to your remote machine
1. Navigate to folder, `~/.ssh/` on Linux device
2. If `~/.ssh/authorized_keys` exists, append the contents of `id_rsa.pub` to the next line.
3. If it does not exist, simply upload `id_rsa.pub` and rename it to, `authorized_keys`
7. DONE!

## Action Items

In order to get this project moving, the following must be done.
Expand Down
1 change: 1 addition & 0 deletions src/VsLinuxDebugger/Commands.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private UserOptions ToUserOptions()

UserPrivateKeyEnabled = Settings.UserPrivateKeyEnabled,
UserPrivateKeyPath = Settings.UserPrivateKeyPath,
UserPrivateKeyPassword = Settings.UserPrivateKeyPassword,
UserName = Settings.UserName,
UserPass = Settings.UserPass,
UserGroupName = Settings.UserGroupName,
Expand Down
10 changes: 8 additions & 2 deletions src/VsLinuxDebugger/Core/SshTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ public void CleanDeploymentFolder(bool fullScrub = false)
public bool Connect()
{
PrivateKeyFile keyFile = null;

try
{
if (_opts.UserPrivateKeyEnabled)
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath);
//// keyFile = new PrivateKeyFile(_opts.UserKeyFilePath, password);
{
if (string.IsNullOrEmpty(_opts.UserPrivateKeyPassword))
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath);
else
keyFile = new PrivateKeyFile(_opts.UserPrivateKeyPath, _opts.UserPrivateKeyPassword);
}

}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/VsLinuxDebugger/Core/UserOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class UserOptions
public string UserPass { get; set; }
public bool UserPrivateKeyEnabled { get; set; }
public string UserPrivateKeyPath { get; set; }
public string UserPrivateKeyPassword { get; set; }
}
}
1 change: 1 addition & 0 deletions src/VsLinuxDebugger/DebuggerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public sealed partial class DebuggerPackage : AsyncPackage
public string UserPass => _optionsPage.UserPass;
public bool UserPrivateKeyEnabled => _optionsPage.UserPrivateKeyEnabled;
public string UserPrivateKeyPath => _optionsPage.UserPrivateKeyPath;
public string UserPrivateKeyPassword => _optionsPage.UserPrivateKeyPassword;

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

Expand Down
7 changes: 6 additions & 1 deletion src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class OptionsPage : DialogPage

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

[Category(Credientials)]
Expand All @@ -45,5 +45,10 @@ public partial class OptionsPage : DialogPage
public string UserPrivateKeyPath { get; set; } = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".ssh\\id_rsa");

[Category(Credientials)]
[DisplayName("SSH Private Key Password (optional)")]
[Description("Private key password (only if it was set).")]
public string UserPrivateKeyPassword { get; set; } = "";
}
}
4 changes: 2 additions & 2 deletions src/VsLinuxDebugger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
2 changes: 1 addition & 1 deletion src/VsLinuxDebugger/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<Metadata>
<Identity Id="VsLinuxDebugger.4d7bf4de-5015-4e24-92c0-7f9f3397b2da" Version="1.3.0" Language="en-US" Publisher="Suess Labs" />
<Identity Id="VsLinuxDebugger.4d7bf4de-5015-4e24-92c0-7f9f3397b2da" Version="1.6.0" Language="en-US" Publisher="Suess Labs" />
<DisplayName>VS Linux Debugger</DisplayName>
<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>
<MoreInfo>https://github.com/SuessLabs/VsLinuxDebug</MoreInfo>
Expand Down

0 comments on commit e74355d

Please sign in to comment.