benpye / wsl-ssh-pageant

A Pageant -> TCP bridge for use with WSL, allowing for Pageant to be used as an ssh-ageant within the WSL environment.
BSD 2-Clause "Simplified" License
612 stars 40 forks source link

Feature request: wsl-ssh-pageant should be able to run in the background #16

Closed mohag closed 5 years ago

mohag commented 5 years ago

When starting the application, it keeps a command-prompt-style window open.

It should be able to run as a service (it might be possible but undocumented?) or minimise to the notification area.

(Other things that would be nice is clarification on the license that the code is released under and a smaller download (None of those affect the functionality though))

benpye commented 5 years ago

Hey,

I've noticed the command-prompt style window thing before. I haven't looked at this too much, but it looks like this should be a relatively easy fix. If you want you could try the instructions at https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application . If you try the instructions and they work please do let me know.

License, I'm happy to say all my code is available under a BSD style license however I can't speak for the code contributed by others. If @doridian agrees (they've made significant code contributions) I'll add a license.txt

As for binary size, this is a .NET core application. By default this means that pretty much an entire .NET runtime is included. I did look at using tools like the IL linker and such to reduce the size but never got around to it. PRs are welcome though. In honestly I'm waiting for Go 1.12 to drop which will add support for AF_UNIX and then I'll probably rewrite this in Go which should produce a significantly smaller binary.

Cheers Ben

On 20 November 2018 06:55:54 GMT, Gert van den Berg notifications@github.com wrote:

When starting the application, it keeps a command-prompt-style window open.

It should be able to run as a service (it might be possible but undocumented?) or minimise to the notification area.

(Other things that would be nice is clarification on the license that the code is released under and a smaller download (None of those affect the functionality though))

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/benpye/wsl-ssh-pageant/issues/16

aviadmini commented 5 years ago

Tried NSubsys from link above, worked like charm Last thing to add is schedule wsl-ssh-pageant to automatically start, probably through windows task scheduler

Doridian commented 5 years ago

License, I'm happy to say all my code is available under a BSD style license however I can't speak for the code contributed by others. If @Doridian agrees (they've made significant code contributions) I'll add a license.txt

I was sure I replied to this, but I must've totally forgotten. That said: The BSD is fine by me.

pkern commented 5 years ago

As I had trouble even installing NSubsys (nuget kept not finding the package), I kept looking and instead found a blog entry that described in its "Autorun" section how to do this with a VB script, which worked fine for me, for what it's worth.

benpye commented 5 years ago

Just got around to adding the license file to the repo. I'm going to try and spend some time this weekend to sort out the issues people are having here.

horenmar commented 5 years ago

That blog post is mine and I definitely support adding that trick into the readme.

benpye commented 5 years ago

Hey all, I just posted a Go version https://github.com/benpye/wsl-ssh-pageant/releases/tag/050219 . Is there anything I can do to make background execution easier? I looked into user services but they don't really seem suitable.

mpotthoff commented 5 years ago

For anyone else looking for a simple solution: I compiled it myself using

go build -ldflags -H=windowsgui

which disables the console window. But you won't be able to see any output then even if it gets started directly from the console.

Sumanai commented 5 years ago

May be run as service?

ghost commented 5 years ago

Tried running as a service and it doesn't work, unfortunately. You will get Error connecting to agent: Permission denied in winssh or error fetching identities: agent refused operation in WSL when attempting to connect even if the service is run as the same user. No idea why, Windows' permission system is a nightmare.

lars18th commented 5 years ago

Hi,

This is my suggestion about this topic:

For the Go version:

I feel it's easy to implement and user friendly. 😉

lars18th commented 5 years ago

Hi,

More or less what you like (run in background):

When you run it from the command line, or using a shortcut, it starts the agent in background; running it until you close your session (or you kill the process).

As a tip it sets the environment variable. However I suggest to support it as commented in #24 (because to unset/clean it as exiting).

Regards.

lars18th commented 5 years ago

Hi,

No one interested on run this tool in the SystemTray?

lars18th commented 5 years ago

For anyone else looking for a simple solution: I compiled it myself using

go build -ldflags -H=windowsgui

which disables the console window. But you won't be able to see any output then even if it gets started directly from the console.

Hi @mpotthoff , Please can you share with us your binary? Until someone will implement the SysTray support it will be preferable to use your binary, as it can run in the background without the requirement of an opened shell window. Regards.

mpotthoff commented 5 years ago

Hey @lars18th I actually already implemented systray support for myself. I just created a fork so you can already try it: https://github.com/mpotthoff/wsl-ssh-pageant/releases/tag/2019-05-08

It can be started exactly like the old version. I myself use a shortcut in %AppData%\Microsoft\Windows\Start Menu\Programs\Startup using this arguments to get it started: --wsl C:\wsl-ssh-pageant\ssh-agent.sock --winssh ssh-pageant. And I also fixed the issue with missing console output caused by the windowsgui build. So if it doesn't show up in your systray you can try to start it in a console window to check for any errors.

I'm going to create a pull request to get this merged. Have fun :)

lars18th commented 5 years ago

Hi @mpotthoff ,

Great! It works perfectly. :+1:

Here one request: Please, add some defaults, as when running it without parameters nothing is displayed. For example, you can use as default "--winssh ssh-pageant". Or perhaps you prefer to print some window with the list of parameters (like a "-help" in command shell).

In any case, please create a PR.

benpye commented 5 years ago

I think we can finally mark this one closed, thanks @mpotthoff !

randallpittman commented 4 years ago

To anyone who finds this useful:

I wanted to have wsl-ssh-pageant start on startup, followed by pageant, and not have any stinkin' cmd windows hanging around the desktop!! Here's what I had to do (there might be simpler way, idk):

Create two batch files.

Replace C:\Portable\OtherPortables with wherever you want to keep wsl-ssh-pageant.

C:\Portable\OtherPortables\launch_wsp.bat

@echo off
setx SSH_AUTH_SOCK \\.\pipe\ssh-pageant
start /B "" "C:\Portable\OtherPortables\wsl-ssh-pageant-amd64-gui.exe" --systray --winssh ssh-pageant

C:\Portable\OtherPortables\launch_wsp_pageant.bat

@echo off
REM Start wsl-ssh-pageant in a cmd instance that closes immediately (but the app keeps running).
cmd /c C:\Portable\OtherPortables\launch_wsp.bat
REM Launch pageant with the ssh key I want added at startup
start "C:\Program Files\PuTTY\pageant.exe" <path_to_my_ppk_file>

Put a shortcut to launch_wsp_pageant.bat in your user Startup folder

loskiq commented 3 years ago

This is a simple implementation of running in the background.

C:\wsl-ssh-pageant\launch_wsp.bat

powershell -WindowStyle Hidden -Command Start-Process -NoNewWindow 'C:\wsl-ssh-pageant\wsl-ssh-pageant.exe' '--winssh ssh-pageant'
SimonAfek commented 2 years ago

As an addendum to @loskiq's comment above, here's a version of their batch file that proxies for both WSL and the built-in Windows 10 SSH, after first deleting the WSL socket file if it already exists (if wsl-ssh-pageant was shut down incorrectly or the like)

del C:\wsl-ssh-pageant\ssh-agent.sock
powershell -WindowStyle Hidden -Command Start-Process -NoNewWindow 'C:\wsl-ssh-pageant\wsl-ssh-pageant-amd64.exe' '--systray --wsl C:\wsl-ssh-pageant\ssh-agent.sock --winssh ssh-pageant'

You can then set this to run automatically on login by creating a shortcut to your batch file, and placing that shortcut in the startup folder (accessible by entering shell:startup in a Win+R "Run"-window).