Missing ~/.ssh Folder in macOS High Sierra

Solution 1:

In macOS, you need to generate your public and private keys from the Terminal. If you haven't yet done this, the .ssh directory will not exist. To create them:

Open the terminal App and enter the following command:

ssh-keygen

You'll get a prompt to choose the location for the keys. It will say “Enter file in which to save the key (/Users/your-username/.ssh/id_rsa)”. If you’re happy with the default location(~/.ssh/) just tap Return. Within your shell the ~ character is equivalent to /Users/your-username/. It stands for your home directory.

It will now say “Enter passphrase (empty for no passphrase):”. Enter your passphrase and press Return. You are asked to re-enter the password to confirm you typed it correctly. This passphrase is used to encrypt the private key and it's recommended you set one.

The prompt will now say “Your identification has been saved in /Users/your-username/.ssh/id_rsa” and “Your public key has been saved in /Users/your-username/.ssh/id_rsa.pub.” It'll then show you the key's Fingerprint and Randomart. The Fingerprint matches the public key and can be used in some situations for authentication, and the Randomart file is designed to match the Fingerprint but be easier to visually identify that it is the right key. You don't need to copy these down for most purposes.

Now you can view the newly-created .ssh directory and find your key within.

You can find a pretty readable guide on the subject here.

Edit: If you want to copy in previously-saved public and private keys:

  • In the terminal, enter cd ~
  • Then mkdir .ssh; chmod 700 ~/.ssh

This will create the directory and give it adequate permissions. Within this directory, you can now paste in your two files which contain the matching public and private key pair. These will be your id_rsa.pub and id_rsa files respectively. Once this is done, double-check their permissions are what they need to be by running:

ls -l ~/.ssh/id_rsa*

The output should look like this(except the numbers 1766 and 388):

-rw------- 1 user root 1766 Oct 04  2017 .ssh/id_rsa
-rw-r--r-- 1 user root  388 Oct 04  2017 .ssh/id_rsa.pub

In case you get something that doesn't look like this, set the permissions of these files with:

$ chown user:user ~/.ssh/id_rsa*
$ chmod 600 ~/.ssh/id_rsa
$ chmod 644 ~/.ssh/id_rsa.pub

Note that with chown user:user ~/.ssh/id_rsa* just above, user is the user account you're logged in with, not literally "user".