diff --git a/docs/GeneratingKeys.md b/docs/GeneratingKeys.md new file mode 100644 index 0000000..b28f9ba --- /dev/null +++ b/docs/GeneratingKeys.md @@ -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] diff --git a/docs/Screenshot-Cmd-GenKey.png b/docs/Screenshot-Cmd-GenKey.png new file mode 100644 index 0000000..fc4d50d Binary files /dev/null and b/docs/Screenshot-Cmd-GenKey.png differ diff --git a/readme.md b/readme.md index c128ffb..a7f079b 100644 --- a/readme.md +++ b/readme.md @@ -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. diff --git a/src/VsLinuxDebugger/Commands.Impl.cs b/src/VsLinuxDebugger/Commands.Impl.cs index bde3f06..4017a71 100644 --- a/src/VsLinuxDebugger/Commands.Impl.cs +++ b/src/VsLinuxDebugger/Commands.Impl.cs @@ -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, diff --git a/src/VsLinuxDebugger/Core/SshTool.cs b/src/VsLinuxDebugger/Core/SshTool.cs index d768827..4cd4939 100644 --- a/src/VsLinuxDebugger/Core/SshTool.cs +++ b/src/VsLinuxDebugger/Core/SshTool.cs @@ -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) { diff --git a/src/VsLinuxDebugger/Core/UserOptions.cs b/src/VsLinuxDebugger/Core/UserOptions.cs index 66fdfc3..65416c3 100644 --- a/src/VsLinuxDebugger/Core/UserOptions.cs +++ b/src/VsLinuxDebugger/Core/UserOptions.cs @@ -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; } } } diff --git a/src/VsLinuxDebugger/DebuggerPackage.cs b/src/VsLinuxDebugger/DebuggerPackage.cs index 546a64f..a5b962b 100644 --- a/src/VsLinuxDebugger/DebuggerPackage.cs +++ b/src/VsLinuxDebugger/DebuggerPackage.cs @@ -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)); diff --git a/src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs b/src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs index 87d72e6..0267efe 100644 --- a/src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs +++ b/src/VsLinuxDebugger/OptionsPages/OptionsPage.Ssh.cs @@ -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)] @@ -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; } = ""; } } diff --git a/src/VsLinuxDebugger/Properties/AssemblyInfo.cs b/src/VsLinuxDebugger/Properties/AssemblyInfo.cs index bc94aae..7b0d307 100644 --- a/src/VsLinuxDebugger/Properties/AssemblyInfo.cs +++ b/src/VsLinuxDebugger/Properties/AssemblyInfo.cs @@ -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")] diff --git a/src/VsLinuxDebugger/source.extension.vsixmanifest b/src/VsLinuxDebugger/source.extension.vsixmanifest index 060aff9..fe7a4ca 100644 --- a/src/VsLinuxDebugger/source.extension.vsixmanifest +++ b/src/VsLinuxDebugger/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + VS Linux Debugger 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! https://github.com/SuessLabs/VsLinuxDebug