Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Trying to Generate a public key for my git. Using Powershell.

PS>ssh-keygen -t rsa -b 4096 -C "my@emailaddress.com"
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Could not create directory '//.ssh': Read-only file system
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Saving key "//.ssh/id_rsa" failed: No such file or directory

If I give a location for the file and run

ssh -vT git@github.com

It doesn't check the custom location for the public key to use

OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [<<ANIPADDRESS>>] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:<<SCAREDTOPUBLISH>>
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug1: Trying private key: /.ssh/id_ecdsa
debug1: Trying private key: /.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

The command could not save your key, likely because it was unable to determine your $HOME directory. Specify a file, at a location where you have write access:

ssh-keygen -t rsa -b 4096 -C "my@emailaddress.com" -f /path/to/key

This will save your private key in /path/to/key and the public key in /path/to/key.pub. When successful, instead of an error message, you will see something like:

Your identification has been saved in /path/to/key.
Your public key has been saved in /path/to/key.pub.
The key fingerprint is:
76:f7:82:04:1e:64:eb:9c:df:dc:0a:6b:26:73:1b:2c
The key's randomart image is:
+--[ RSA 2048]----+
|        o        |
|       o .       |
|        +        |
|       + +       |
|        S o .    |
|       . = = o   |
|        E * + o  |
|        o.++ o   |
|         *o..    |
+-----------------+

And then, to make ssh look for the file at the custom location, use the -i flag:

ssh -i /path/to/key -vT git@github.com

Alternatively, if you have an authentication agent running, you can add your key to the agent with:

ssh-add /path/to/key

Once your key is stored by the agent, you can simply do:

ssh -T git@github.com

The response should look something like:

Hi USER! You've successfully authenticated, but GitHub does not provide shell access.

And you can go ahead and clone your repository with:

git clone git@github.com:USER/REPO
                I get an error: "permission denied public key".  You missed the step where you have to login to your Github page and add the id_rsa.pub key!
– IgorGanapolsky
                Aug 12, 2016 at 18:59
                @IgorGanapolsky I don't see how that's related to this question. I suggest to ask a new question about it, and make sure to include all necessary details, such as the commands you ran, and their complete output. Good luck.
– janos
                Aug 12, 2016 at 19:04
                @IgorGanapolsky This question was specifically about a “no such file or directory” issue when using the ssh-keygen command. Not meant as a tutorial of authentication with GitHub, there are many other answers for that, as well as GitHub's own excellent documentation.
– janos
                Aug 12, 2016 at 19:12
                I get a key_load_public: No such file or directory error when it looks for identity file /home/yuri/.ssh/id_rsa-cert type -1
– yuriploc
                Aug 19, 2017 at 18:27
                In my case I tried to pass a path relative to my home directory like ~/.ssh/foo to ssh-keygen presuming the user would get expanded to my current user, however, it doesn't seem to support this.  Changing the path to absolute /Users/myuser/.ssh/foo does work.
– Taylor D. Edmiston
                Jun 5, 2019 at 16:44

For me, the ssh-keygen command appears to fail only when using cmd:

Your identification has been saved in [...]/.ssh/id_rsa. fdopen [...]/.ssh/id_rsa.pub failed: No such file or directory

The private key is generated, but the public key file is created with 0 bytes.

If I run the command in Git Bash on Windows, it works.

i tried this instead of ~/.ssh/whatever_file_name

this code worked for me

ssh-add /Users/<user>/.ssh/id_ed25519

replace <user> with your user folder name...

You are getting the error: Saving key "//.ssh/id_rsa" failed: No such file or directory

Seems to me like you need to create folder .ssh

Try mkdir .ssh, and then run ssh-keygen -t rsa again.