Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to kill ssh-agent not working #863

Closed
cheuer opened this issue Sep 14, 2016 · 13 comments
Closed

Option to kill ssh-agent not working #863

cheuer opened this issue Sep 14, 2016 · 13 comments

Comments

@cheuer
Copy link

@cheuer cheuer commented Sep 14, 2016

Versions

ConEmu build: 160913 x64
OS version: Windows 10 x64 version 1607
Used shell version (Far Manager, git-bash, cmd, powershell, cygwin, whatever): GNU bash, version 4.3.42(4)-release (x86_64-unknown-cygwin)

Problem description

New option introduced in 160913 to kill ssh-agent processes when closing conemu doesn't seem to have any effect; conemu kills all ssh-agent processes no matter what.

Steps to reproduce

  1. Ensure "Kill ssh-agent with ConEmu" is disabled in Settings > Features is unchecked
  2. Start ssh-agent process
  3. Close conemu

Actual results

Started ssh-agent process is killed

Expected results

ssh-agent should continue running

Additional files

Settings and logfiles: https://www.dropbox.com/s/bwcn4zlc8fnr6er/ConEmuLogs_issue301.zip?dl=0

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Sep 14, 2016

Well, I'll fix it.
But why do you want to leave ssh-agent running after ConEmu exit?

Loading

@cheuer
Copy link
Author

@cheuer cheuer commented Sep 14, 2016

Loading

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Sep 14, 2016

Than, where do you store and initialize SSH_*** environment variables?

Loading

@cheuer
Copy link
Author

@cheuer cheuer commented Sep 15, 2016

I have the following in my .bashrc file. It writes the output of ssh-agent to ~/.ssh-agent and sources that if ssh-add fails on subsequent calls.

alias scp='__ssh_agent && scp'
alias ssh='__ssh_agent && ssh'

function __ssh_agent() {
    # If no SSH agent is already running, start one now. Re-use sockets so we never
    # have to start more than one session.

    ssh-add -l >/dev/null 2>&1
    result=$?
    if [ $result = 2 ]; then
        # read ssh-agent config from file and retry
        [ -r ~/.ssh-agent ] && source ~/.ssh-agent >/dev/null
        ssh-add -l >/dev/null 2>&1
        result=$?
        if [ $result = 2 ]; then
            ssh-agent > ~/.ssh-agent
            source ~/.ssh-agent >/dev/null
            ssh-add
        fi
    fi
    if [ $result = 1 ]; then
        ssh-add
    fi
}

Loading

@cheuer
Copy link
Author

@cheuer cheuer commented Sep 15, 2016

Updated to 160914 this morning and can confirm the option works now. Thanks!

Loading

@bytefluxio
Copy link

@bytefluxio bytefluxio commented Jun 3, 2021

I think there's regression here. Doesn't work for me. Neither with an ssh-agent running detached with nohup, nor just as is.

I would be happy with not having detached process (nohup) being closed as long as conemu is still running, when closing a tab. :( Or at least as long as the same shell is running.

I'm sharing ssh-agents between tabs, so as not to constantly reenter passwords for private ssh-keys and as is I have to keep the "main" tab running to enable this.

I checked with msys2 without conemu and there nohup works normally (keeps running even if all msys2 windows are closed)

Loading

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Jun 4, 2021

@bytefluxio How do you run ssh-agent and what is shown in Settings/Info?

Loading

@bytefluxio
Copy link

@bytefluxio bytefluxio commented Jun 4, 2021

Testing this with two windows, works the same with two tabs, but harder to make screenshots ;)

Two shells, one starts ssh with nohup, both set their SSH_AUTH_SOCK and connect

(Also: Settings>Info, can't see the ssh-agent on the second terminal, but ps -a from within the shell can)

ConEmu64_5aakzzSB5j

Attempting to close first shell (the one that originally started the ssh-agent, you won't get the popup if you try to close the second one first) - Had to click the terminate button or else shell wouldn't close

ConEmu64_C6Y6TkW0uO

Closed first window, ssh-agent not running, can't connect

ConEmu64_mNhR1UPgoI

Loading

@bytefluxio
Copy link

@bytefluxio bytefluxio commented Jun 4, 2021

nohup works on other terminals, such as msys2 directly or windows terminal.

Loading

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Jun 5, 2021

  1. Where is "nohup" in your examples?
  2. ConEmu does not "close" ssh-agent in your case, it's closed by Windows. That's because ssh-agent.exe is started in the existing console, and definitely when the console is closed, all processes assigned to your console are closed too.

Actually, you misunderstood the meaning of the checkbox "Kill ssh-agent with ConEmu". It does exactly what it says, when it's checked, ConEmu kills all spawned processes (additional action). When the checkbox is unchecked, ConEmu does nothing!
In your cases, as I've said, ssh-agents are killed by Windows, as they are started inside console.

The description of how I use ssh-agent is here: https://conemu.github.io/en/SshAgent.html

Loading

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Jun 5, 2021

(Also: Settings>Info, can't see the ssh-agent on the second terminal, but ps -a from within the shell can)

That's because Settings/Info shows exactly the processes returned by the GetConsoleProcessList. ConEmu does not do any magic here. You see ssh-agent in the exact console where it's running. When you close this console, all running processes are killed automatically by Windows.

Loading

@bytefluxio
Copy link

@bytefluxio bytefluxio commented Jun 6, 2021

  1. Starting ssh-agent in the example is done via nohup ssh-agent -c > ~ /.ssh/environment
  2. Starting a msys2 console without conemu, does not kill a nohup process on exit. Doing the same in another terminal like "Microsoft Terminal" also does not kill the process. The confirmation dialog that appears to kill processes on console closure, does not differentiate between nohup processes and others.

I'm using Microsoft Terminal for now, as that means I only have to enter the password for my ssh keys once, per pc reboot.
I'm currently a little swamped on work at work and at home, but if this is still an issue in October, I'd happly investigate more and create a PR regarding the nohup issue.

Loading

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Jun 6, 2021

Starting a msys2 console without conemu

That is not correct comparison. The proper comparison will be if you start msys2 console in ConEmu using the Connector. Microsoft Terminal could work the same way, omitting the RealConsole interface, which leads to "empty" GetConsoleProcessList.

And again, my personal solution is here: https://conemu.github.io/en/SshAgent.html

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants