Find Ssh Key In Mac Manual

Active2 years ago

If you need to get ssh keys copied from client to server but ssh-copy-id isn't an option, you'll have to go the manual route. Here's how to do it. Secure Shell is one of those tools you will.

I understand that since Mac OS X Leopard the Keychain has supported storing SSH keys. Could someone please explain how this feature is supposed to work.

  1. Pick the user you want to create keys for and choose the Generate SSH Keys button from the drop-down menu. This will create the.sftp folder in the home folder of the user, and the public key will be added to the authorizedkeys file and placed inside the.sftp folder ( e.g.
  2. Ssh-keygen can create RSA keys for use by SSH protocol version 1 and RSA or DSA keys for use by SSH protocol version 2. The type of key to be generated is specified with the -t option. If invoked without any arguments, ssh-keygen will generate an RSA key for use in SSH protocol 2 connections.

I have some RSA keys that I've generated stored in my ~/.ssh directory for accessing various servers. I don't have passphrases set on those keys. Currently in order to log in to those servers I use the following commands in the Terminal:

(I've written some Bash functions to make this easier.)

Is there a better way to do this using the Keychain?

John Topley
John TopleyJohn Topley
6983 gold badges13 silver badges22 bronze badges

9 Answers

For it to work, the $SSH_AUTH_SOCK environment variable should be pointed to /tmp/launch-xxxxxx/Listeners. This is supposed to be done automatically when you log in. The listener on that socket speaks the ssh-agent protocol.

Your bash scripts are starting your own ssh agent (spelled ssh-agent, not ssh_agent) and overriding the existing ssh-agent that is set up for you at login.

Also, the whole point of the keychain is to store the passwords to your ssh keys, but you say that you don't have passphrases set on those keys, so I'm not sure what you are expecting out of the keychain integration.

Finally, when you first log in, you probably won't see a ssh-agent process. That process will be started automatically by launch services the first time something tries to read that socket in /tmp.

RudedogRudedog
Ssh

As of the Leopard release of OS X, ssh-agent is more tightly integrated with Keychain. It is possible to store the passphrases of all of your SSH keys securely in Keychain, from which ssh-agent will read them on startup. The bottom line is that it is simple to secure your keys with passphrases, but never have to type the passphrase to use them! Here is how:

Add the pass phrase to each ssh key to keychain: (option -k loads plain private keys only, skips certificates)

(note that's a capital K)

Whenever you reboot your Mac, all the SSH keys in your keychain will be automatically loaded. You should be able to see the keys in the Keychain Access app, as well as from the command line via:

jeffmccjeffmcc
2,6312 gold badges10 silver badges3 bronze badges

As of macOS Sierra, ssh-agent no longer auto-loads previously loaded ssh keys when you log in to your account. This is intentional on Apple part, they wanted to re-align with the mainstream OpenSSH implementation. [1]

As explained here, this is the recommended method since macOS 10.12.2:

  1. Add the following lines to your ~/.ssh/config file:

  2. Any key you add to the ssh-agent using the ssh-add /path/to/your/private/key/id_rsa command will be automatically added to the keychain, and should be autoloaded upon reboot.

The following is deprecated (kept for reference).

To go back to the previous behavior, you'd want to run the ssh-add -A command (which auto-loads all the ssh keys that have pass-phrases on your keychain) when you log in. To do that, follow these steps:

  1. First, add all the keys you want to auto-load to the ssh-agent using the ssh-add -K /absolute/path/to/your/private/key/id_rsa command. The -K argument ensures that the key pass-phrase is added to macOS's keychain. Make sure you use the absolute path to the key. Using a relative path will make the auto-launched script not to find your key.

  2. Make sure all of your keys are shown as added when you type ssh-add -A.

  3. Create a file called com.yourusername.ssh-add.plist in ~/Library/LaunchAgents/ with the contents below. Plist files such as this one are used by launchd to run scripts when you log in. [2][3]

  4. Tell launchd to load the plist file you just created by executing: launchctl load ~/Library/LaunchAgents/com.yourusername.ssh-add.plist.

And you should be all set.

Mac Os Ssh Keys

Community
Ricardo Sanchez-SaezRicardo Sanchez-Saez
1,0301 gold badge9 silver badges18 bronze badges

There is a simpler way than Ricardo's answer to persist your password between sessions/restarts of your Mac running 10.12 Sierra.

  1. ssh-add -K ~/.ssh/id_rsa
    Note: change the path to where your id_rsa key is located.
  2. ssh-add -A
  3. Create (or edit if it exists) the following ~/.ssh/config file:

    Now the password is remembered between restarts!

Apple purposely changed the behaviour for ssh-agent in macOS 10.12 Sierra to no longer automatically load the previous SSH keys, as noted in this OpenRadar, Twitter discussion, and Technical Note from Apple. The solution above will mimic the old behaviour of El Capitan and remember your password.

Community
ChrisJFChrisJF

Note: for macOS Sierra, please refer to the more recent answer by ChrisJF.

The [answer by Jeff McCarrell][2] is correct, except that the command to add the pass phrase contains an en dash instead of a hyphen, i.e. –K instead of -K, causing a message to the effect of –K: No such file or directory.It should read:

simonairsimonair

I suspect you aren't using the default ssh command. Do you have ssh installed via ports? Try which ssh to see which ssh command you are using.

Usually it should display a dialog box asking for you password, if it isn't already stored in you keychain.

OllyOlly
4713 gold badges6 silver badges10 bronze badges

I had a similar problem while trying to login using a client ssh cert. In this specific case it was for accessing a git repository. This was the situation:

  • Key was saved in ~/.ssh/
  • The private key has a passphrase.
  • The passphrase is stored in the OS X login keychain. ~/Library/Keychains/login.keychain
  • The connection was as follows: my mac -> remote mac -> git/ssh server
  • Mac OS X 10.8.5

When I connected to remote mac using remote desktop, I didn't have a problem. However when connecting with SSH to the remote mac, I was asked for the ssh passphrase every time. The following steps solved it for me.

  1. security unlock-keychain The passphrase is stored in the login keychain. This unlocks it and enables ssh-agent to access it.
  2. eval `ssh-agent -s` Starts ssh-agent for shell use. It will get the passphrase from the keychain and use it to unlock the private ssh key.
  3. Establish the ssh/git connection and do my work.
  4. eval `ssh-agent -k` Kill the running ssh-agent.
  5. security lock-keychain Lock the keychain again.
orkodenorkoden

See also:

... adding this note as more detail was requested: the 'security' command is capable of importing keys (and other things) directly into Keychains. The nice thing is that unlike ssh-add, you are able to specify the keychain. This makes it possible to import directly into the system Keychain ('man security' to learn how)

xaphodxaphod

The best and Apple intended solution (since macOS 10.12.2) is described here

So just do the following:

echo 'UseKeychain yes' >> ~/.ssh/config

Community
BenBen

Not the answer you're looking for? Browse other questions tagged macossshkeychain or ask your own question.

Active2 months ago

I've just generated my RSA key pair, and I wanted to add that key to GitHub.

I tried cd id_rsa.pub and id_rsa.pub, but no luck. How can I access my SSH public key?

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
sscirrussscirrus
29k41 gold badges118 silver badges207 bronze badges

17 Answers

cat ~/.ssh/id_rsa.pub or cat ~/.ssh/id_dsa.pub

You can list all the public keys you have by doing:

$ ls ~/.ssh/*.pub

Mitch DempseyMitch Dempsey
28.1k5 gold badges58 silver badges71 bronze badges

Copy the key to your clipboard.

Warning: it's important to copy the key exactly without adding newlines or whitespace. Thankfully the pbcopy command makes it easy to perform this setup perfectly.

And you can paste it wherever you need.

To get a better idea of the whole process, check this: Generating SSH Keys.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
D_DD_D

Find Ssh Key In Mac Manual 2017

5,79311 gold badges33 silver badges60 bronze badges

You may try to run the following command to show your RSA fingerprint:

or public key:

If you've the message: 'The agent has no identities.', then you've to generate your RSA key by ssh-keygen first.

kenorbkenorbFind ssh key in mac manual free
80k34 gold badges447 silver badges461 bronze badges

If you're on Windows use the following, select all, and copy from a Notepad window:

If you're on OS X, use:

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
Find ssh key in mac manual 2017
nsuintegernsuinteger

Here's how I found mine on OS X:

  1. Open a terminal
  2. (You are in the home directory) cd .ssh (a hidden directory)
  3. pbcopy < id_rsa.pub (this copies it to the clipboard)

If that doesn't work, do an ls and see what files are in there with a .pub extension.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
MarkMark

After you generate your SSH key you can do:

which will copy your ssh key into your clipboard.

BrettBrett

If you are using Windows PowerShell, the easiest way is to:

That will copy the key to your clipboard for easy pasting.

So, in my instance, I use ed25519 since RSA is now fairly hackable:

Because I find myself doing this a lot, I created a function and set a simple alias I could remember in my PowerShell profile (learn more about PowerShell profiles here. Just add this to your Microsoft.PowerShell_profile.ps1:

Then, in a PowerShell console, run . $profile to load the functions. Then from now on all you will need to do is run sshkey, and then paste the key into wherever you need via the clipboard.

Peter Mortensen

Find Ssh Key In Mac Manual Software

14.4k19 gold badges88 silver badges117 bronze badges
Riley TaylorRiley Taylor

Open your id_dsa.pub or some_name.pub file with gedit and copy-paste the contents!

Just use:

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
sbdv0sbdv0

Use:

Then copy the entire file without any spaces. Click your icon at the top right of the GitHub page, go to settings, and add ssh.

Paste the copy into the space. It may prompt for your GitHub password. Enter it. Save.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
yavorcikyavorcik

On terminal cat ~/.ssh/id_rsa.pub

explanation

  1. cat is a standard Unix utility that reads files and prints output
  2. ~ Is your Home User path
  3. /.ssh - your hidden directory contains all your ssh certificates
  4. id_rsa.pub OR id_dsa.pub are RSA public keys, (the private key located on the client machine). the primary key for example can be used to enable cloning project from remote repository securely to your client end point.
avivamgavivamg

It can be found on this path (default path):

Find Ssh Key In Mac Manual Downloads

john is your Mac username.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
SpydySpydy

The following command will save the SSH key on the clipboard. You only need to paste at the desired location.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
Prabhat KaseraPrabhat Kasera

Find Ssh Key In Mac Manual Download

If you're using windows, the command is:

it should print the key (if you have one). You should copy the entire result.If none is present, then do:

Jghayes525Jghayes525
Nick WoodNick Wood

On a Mac, you can do this to copy it to your clipboard (like cmd + c shortcut)
cat ~/Desktop/ded.html | pbcopy
pbcopy < ~/.ssh/id_rsa.pub

Find Ssh Key In Mac Manual Pdf

and to pastepbpaste > ~Documents/id_rsa.txt

or, use cmd + v shorcutto paste it somewhere else.

Find Ssh Key In Mac Manual Free

~/.ssh is the same path as /Users/macbook-username/.ssh
You can use Print work directory: pwd command on terminal to get the path to your current directory.

Jun711Jun711
1,0533 gold badges11 silver badges31 bronze badges

In UBUNTU +18.04

And After that Just Copy And Paste

or

Shabeer ShaShabeer Sha

I use Git Bash for my Windows.

$ eval $(ssh-agent -s) //activates the connection

  • some output

$ ssh-add ~/.ssh/id_rsa //adds the identity

  • some other output

$ clip < ~/.ssh/id_rsa.pub //THIS IS THE IMPORTANT ONE. This adds your key to your clipboard. Go back to GitHub and just paste it in, and voilá! You should be good to go.

J.WJ.W

Not the answer you're looking for? Browse other questions tagged gitsshrsa or ask your own question.