18

I'm having some issues with SSH KeychainIntegration in OS X Mavericks. I've tried poking around Apple's support site, but haven't seen anyone having my issue. I have seen lots of people who seemingly don't know how to use SSH that well, so I decided to try another community.

First, my configuration is working. I am able to use my key pair and ssh to hosts as I need to, with my credentials being cached in the agent. I am able to see my cached credentials via "ssh-add -l", as expected. I am prompted to input my password by an OS X-style dialog, with a checkbox that says "Remember password in my keychain". I usually ignore this checkbox, but when I check it, I do see my key stored in the keychain. This key stored in the keychain is seemingly never used, however, since I have a password on it. At least that's what I've gleaned from various things I've read. When I enter my password into the dialog, and the key is cached in the agent, I successfully connect, but not before being told "Saving password to keychain failed". Seeing this error message is what led me to investigate further; I don't like getting an error every time I connect.

Things get interesting when looking at the manpage SSH_CONFIG(5). Two options for dealing with the keychain exist, specific to Apple: AskPassGUI, and KeychainIntegration. You're able to toggle these in ~/.ssh/config, and doing so yields some interesting results.

Setting AskPassGUI to no, you'll no longer be prompted with an OS X-style dialog, instead an input text line in your terminal. No biggie. But if you do this, then ssh-agent will not cache your credentials. This is plainly broken, and frustrating because I could easily live with the text prompt if the credentials were cached.

Setting KeychainIntegration to no, ssh throws a hard error, as follows:

~/.ssh/config: line 11: Bad configuration option: KeychainIntegration
~/.ssh/config: terminating, 1 bad configuration options

My question, simply, is this: Is there a way to actually disable OS X Keychain Integration for SSH?

  • Nice question, I don't have an immediate answer, but hope with the votes it has, it will pop up on someone's radar. I can confirm the bug on my build of OS X with just a one line config file - setting the value to yes or no fails as described. – bmike Feb 20 '14 at 11:55
  • A point of clarification: I only receive the message "Saving password to keychain failed" when ssh-add successfully caches credentials. I don't see it on every connection attempt, which is how it reads, when I re-read it. With cached credentials, it simply connects quietly, as you would expect. – Jim Feb 20 '14 at 23:19
7

Based on the source code for the current version of SSH that's shipping with Mavericks (located here), it appears that the functionality of the config option KeychainIntegration has not yet been implemented. I'm making this assumption based on the contents of openssh/readconf.h, which does not reference the KeychainIntegration option. It does, however, reference the askpassgui option. Checking the "keywords" struct in that file does indeed show that the keychainintegration option is not present (which in turn implies that the oBadOption (NULL) op code would be returned).

Another clue implying that the functionality you desire is not implemented in the way the man page specifies is the file: openssh/keychain.c. The source code actually shows that the defaults system (i.e., Property List files) is being used to store settings related to KeychainIntegration. Specifically, lines from the store_in_keychain function reference KeychainIntegration:

/* Bail out if KeychainIntegration preference is -bool NO */
if (get_boolean_preference("KeychainIntegration", 1, 1) == 0) {
    fprintf(stderr, "Keychain integration is disabled.\n");
    goto err;
}

Here is the corresponding get_boolean_preference function. Note that it's using CFPreferencesCopyAppValue to obtain a boolean from the "org.openbsd.openssh" application identifier:

#if defined(__APPLE_KEYCHAIN__)

static int get_boolean_preference(const char *key, int default_value,
int foreground)
{
int value = default_value;
CFStringRef keyRef = NULL;
CFPropertyListRef valueRef = NULL;

keyRef = CFStringCreateWithCString(NULL, key, kCFStringEncodingUTF8);
if (keyRef != NULL)
    valueRef = CFPreferencesCopyAppValue(keyRef,
        CFSTR("org.openbsd.openssh"));
if (valueRef != NULL)
    if (CFGetTypeID(valueRef) == CFBooleanGetTypeID())
        value = CFBooleanGetValue(valueRef);
    else if (foreground)
        fprintf(stderr, "Ignoring nonboolean %s preference.\n", key);

if (keyRef)
    CFRelease(keyRef);
if (valueRef)
    CFRelease(valueRef);

return value;
}

#endif

This might imply that you can disable the KeychainIntegration functionality for yourself by performing this defaults command:

defaults write org.openbsd.openssh KeychainIntegration -bool NO

or to set it for all users:

sudo defaults write /Library/Preferences/org.openbsd.openssh KeychainIntegration -bool NO

  • 2
    You dug deep, and I appreciate it. I tried setting KeychainIntegration to NO via defaults as you suggested. ssh then behaves as if I'd set AskPassGUI in ~/.ssh/config -- no credentials are cached, and I'm prompted for the passphrase all the time. Less than useful. Still, I think you've answered the question, and the answer is, simply, "It can be disabled, but it isn't fully implemented, and you probably won't like the results." – Jim Mar 4 '14 at 20:29
  • Thank you so much I was searching all over to find an answer to this. Since I have a custom .zshrc file that I port between mac and linux it was driving me nuts that keychain was taking control of managing ssh-agent and the added keys. – LF4 Oct 16 '14 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .