.ssh directory not being created .ssh directory not being created unix unix

.ssh directory not being created


I am assuming that you have enough permissions to create this directory.

To fix your problem, you can either ssh to some other location:

ssh user@some.host

and accept new key - it will create directory ~/.ssh and known_hosts underneath, or simply create it manually using

mkdir ~/.sshchmod 700 ~/.ssh

Note that chmod 700 is an important step!

After that, ssh-keygen should work without complaints.


Is there a step missing?

Yes. You need to create the directory:

mkdir ${HOME}/.ssh

Additionally, SSH requires you to set the permissions so that only you (the owner) can access anything in ~/.ssh:

% chmod 700 ~/.ssh

Should the .ssh dir be generated when I use the ssh-keygen command?

No. This command generates an SSH key pair but will fail if it cannot write to the required directory:

% ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): /Users/tmp/does_not_existEnter passphrase (empty for no passphrase): Enter same passphrase again: open /Users/tmp/does_not_exist failed: No such file or directory.Saving the key failed: /Users/tmp/does_not_exist.

Once you've created your keys, you should also restrict who can read those key files to just yourself:

% chmod -R go-wrx ~/.ssh/*


As a slight improvement over the other answers, you can do the mkdir and chmod as a single operation using mkdir's -m switch.

$ mkdir -m 700 ${HOME}/.ssh

Usage

From a Linux system

$ mkdir --helpUsage: mkdir [OPTION]... DIRECTORY...Create the DIRECTORY(ies), if they do not already exist.Mandatory arguments to long options are mandatory for short options too.  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask......