It appears you are set up to deploy to GitHub and as such that requires you to have a GitHub user set so it knows where to deploy to. Depending on your environment you need to set that environment variable before running the command:

export GIT_USER=yourusername
Answer from James Gray on Stack Overflow
🌐
GitHub
github.com › facebook › docusaurus › issues › 3389
Error: Please set the GIT_USER environment variable! · Issue #3389 · facebook/docusaurus
September 2, 2020 - 🐛 Bug Report I can not deploy my docusaurus site. I try: cmd /C "set "GIT_USER=novoselovaleksandr" USE_SSH=true && yarn deploy" and i get an error: This is a part of my ...
Author: facebook
Discussions

Git clone with custom SSH using GIT_SSH error - Stack Overflow
I am trying to clone a Git repo using a custom SSH command. I set the SSH command in the GIT_SSH environmental variably be running export GIT_SSH="/usr/bin/ssh -o StrictHostKeyChecking=no -i /hom... More on stackoverflow.com
🌐 stackoverflow.com
git - Set GIT_SSH Environment Variable in Gitconfig - Stack Overflow
Is there a way to set the GIT_SSH environment variable in the gitconfig file? More on stackoverflow.com
🌐 stackoverflow.com
Newest 'environment-variables' Questions - Page 3 - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
version control - "Cannot spawn ssh" when connecting to Github, but ssh -T git@github.com works? - Stack Overflow
I am having a hard time getting Github (+Netbeans to work). I want to use ssh with git (on Windows 7) to, e.g., commit or clone a project, but I keep getting this error message : $ git clone git@ More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › facebook › docusaurus › issues › 3454
[v2]: Not require GIT_USER when using ssh · Issue #3454 · facebook/docusaurus
September 15, 2020 - There was an error while loading. Please reload this page. ... proposalThis issue is a proposal, usually non-trivial changeThis issue is a proposal, usually non-trivial change ... GIT_USER environment variable is required for deploying, but in case of SSH, I think there is no problem without GIT_USER.
Author: facebook
Top answer
1 of 6
106

You cannot provide options in the GIT_SSH environment variable; from the git man page:

   GIT_SSH
       If this environment variable is set then git fetch and git push will use this command instead of ssh when they need to connect
       to a remote system. The $GIT_SSH command will be given exactly two arguments: the username@host (or just host) from the URL
       and the shell command to execute on that remote system.

       To pass options to the program that you want to list in GIT_SSH you will need to wrap the program and options into a shell
       script, then set GIT_SSH to refer to the shell script.

One option is to add a stanza to your .ssh/config file with the appropriate configuration:

Host bitbucket.org
  StrictHostKeyChecking no
  IdentityFile /home/me/my_private_key

Another option is to point GIT_SSH to a shell script that does what you want. E.g., in /home/me/bin/bitbucket_ssh, put:

#!/bin/sh
exec /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key "$@"

And then point GIT_SSH at /home/me/bin/bitbucket_ssh.

I prefer using .ssh/config when possible, because this avoids the need to create a per-destination script for each remote.

2 of 6
36

Note that starting with git 2.3+ (Q1 2015), what you initially tried would work, with the new environment variable GIT_SSH_COMMAND.

See commit 3994276 from Thomas Quinot (quinot):

git_connect: set ssh shell command in GIT_SSH_COMMAND

It may be impractical to install a wrapper script for GIT_SSH when additional parameters need to be passed.
Provide an alternative way of specifying a shell command to be run, including command line arguments, by means of the GIT_SSH_COMMAND environment variable, which behaves like GIT_SSH but is passed to the shell.

The special circuitry to modify parameters in the case of using PuTTY's plink/tortoiseplink is activated only when using GIT_SSH; in the case of using GIT_SSH_COMMAND, it is deliberately left up to the user to make any required parameters adaptation before calling the underlying ssh implementation.

GIT_SSH_COMMAND:

If either of these environment variables is set then 'git fetch' and 'git push' will use the specified command instead of 'ssh' when they need to connect to a remote system.
The command will be given exactly two or four arguments:

  • the 'username@host' (or just 'host') from the URL and the shell command to execute on that remote system, optionally preceded by '-p' (literally) and
  • the 'port' from the URL when it specifies something other than the default SSH port.

$GIT_SSH_COMMAND takes precedence over $GIT_SSH, and is interpreted by the shell, which allows additional arguments to be included.
$GIT_SSH on the other hand must be just the path to a program (which can be a wrapper shell script, if additional arguments are needed).

Top answer
1 of 16
1119

In ~/.ssh/config, add:

Host github.com
 HostName github.com
 IdentityFile ~/.ssh/id_rsa_github

If the config file is new, check access permissions using

stat -c %a ~/.ssh/config

if returns NOT 600, you should do

chmod 600 ~/.ssh/config

Now you can do git clone [email protected]:{ORG_NAME}/{REPO_NAME}.git

  • Where {ORG_NAME} is your GitHub user account (or organization account)'s GitHub URI name.
    • Note that there is a colon : after github.com instead of the slash / - as this is not a URI.
  • And {REPO_NAME} is your GitHub repo's URI name
  • For example, for the Linux kernel this would be git clone [email protected]:torvalds/linux.git).

NOTE: On Linux and macOS, verify that the permissions on your IdentityFile are 400. SSH will reject, in a not clearly explicit manner, SSH keys that are too readable. It will just look like a credential rejection. The solution, in this case, is:

chmod 400 ~/.ssh/id_rsa_github
2 of 16
803

Environment variable GIT_SSH_COMMAND

From Git version 2.3.0, you can use the environment variable GIT_SSH_COMMAND like this:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example" git clone example

Note that -i can sometimes be overridden by your config file, in which case, you should give SSH an empty config file, like this:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone [email protected]:example/example.git

Configuration core.sshCommand

Since Git version 2.10.0, you can configure this per repo or globally, using the core.sshCommand setting. There's no more need to use the environment variable. Here's how you clone a repo and set this configuration at the same time:

git clone -c "core.sshCommand=ssh -i ~/.ssh/id_rsa_example -F /dev/null" [email protected]:example/example.git
cd example/
git pull
git push

If the repo already exists, run:

git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"

The configuration is saved in .git/config

🌐
Docusaurus
v1.docusaurus.io › docs › en › publishing
Publishing your site · Docusaurus
April 5, 2021 - Now you have to specify the git user as an environment variable, and run the script publish-gh-pages · To run the script directly from the command-line, you can use the following, filling in the parameter values as appropriate. ... GIT_USER=<GIT_USER> \ CURRENT_BRANCH=master \ USE_SSH=true \ yarn run publish-gh-pages # or `npm run publish-gh-pages`
🌐
Git
git-scm.com › book › en › v2 › Git-Internals-Environment-Variables
Git - Environment Variables
$ GIT_TRACE_SETUP=true git status ... 'origin/master'. nothing to commit, working directory clean · GIT_SSH, if specified, is a program that is invoked instead of ssh when Git tries to connect to an SSH host....
🌐
Tankywoo
blog.tankywoo.com › 2014 › 04 › 15 › git-use-specified-ssh-key.html
Git use Specified SSH Key | Blog·Tanky Woo
April 15, 2014 - GIT_SSH If this environment variable is set then git fetch and git push will use **this command** instead of ssh when they need to connect to a remote system. The $GIT_SSH command will be given exactly two arguments: the username@host (or just host) from the URL and the shell command to execute ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › tagged › environment-variables
Newest 'environment-variables' Questions - Page 3 - Stack Overflow
So i added the .env file in gitignore , and then pushed it to main branch . because of my disk error my files got deleted , so i now cloned the project , and due to security reasons i wanted to change ...
🌐
Matthew Petroff
mpetroff.net › 2024 › 12 › making-git-prompt-for-ssh-username
Making Git prompt for SSH username | Matthew Petroff
December 31, 2024 - A crude solution was to set GIT_SSH_COMMAND='ssh -l $USER', but this requires the user to remember to run, e.g., USER=username git pull, although this can be helped by setting USER='Prefix_git_with_"USER=yourusername"!!!!!!!!' in .bashrc. After much trial and error, I arrived at the solution ...
🌐
Stack Overflow
stackoverflow.com › questions › 64686945 › cannot-permanently-set-git-ssh-variable-in-git-for-windows-10
gitlab - Cannot permanently set GIT_SSH variable in Git for Windows 10 - Stack Overflow
Hit Win-button and type in "environment variables" and open the suggested item to check. Lasse V. Karlsen – Lasse V. Karlsen · 2020-11-05 08:37:45 +00:00 Commented Nov 5, 2020 at 8:37 ... Either this variable is set as a User or System environment variable, or it is set in your ~/.bashrc in a Putty session.
🌐
GitHub
github.com › vladmandic › sdnext › issues › 3746
[Feature]: Add support for git+ssh · Issue #3746 · vladmandic/sdnext
February 5, 2025 - Please make sure you have the correct access rights and the repository exists. Problem reproduced. Let's fix it by explicitly specifying an SSH identity file with an environment variable:
Author: vladmandic
Top answer
1 of 3
24

You don't have to set an environment variable anymore in Windows.

With git 2.10+ (Q3 2016), you also have the possibility to set a config for GIT_SSH_COMMAND, which is easier than an environment variable (and can be set globally, or locally for a specific repo)

See commit 3c8ede3 (26 Jun 2016) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit dc21164, 19 Jul 2016)

A new configuration variable core.sshCommand has been added to specify what value for GIT_SSH_COMMAND to use per repository.

core.sshCommand:

If this variable is set, git fetch and git push will use the specified command instead of ssh when they need to connect to a remote system.
The command is in the same form as the GIT_SSH_COMMAND environment variable and is overridden when the environment variable is set.

It means the git push can be:

cd /path/to/my/repo
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' 
# later on
git push origin master

With Git 2.16 (Q1 2018), you will have a new mechanism to upgrade the wire protocol in place is proposed and demonstrated that it works with the older versions of Git without harming them.

See commit 6464679 (16 Oct 2017), and commit 0cd8328 (26 Sep 2017) by Jonathan Tan (jhowtan).
See commit 94b8ae5, commit 3c88ebd, commit 19113a2, commit 0c2f0d2, commit 2609043, commit aa9bab2, commit dfe422d, commit 373d70e, commit 5d2124b (16 Oct 2017) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit 4c6dad0, 06 Dec 2017)

ssh: introduce a 'simple' ssh variant

When using the 'ssh' transport, the '-o' option is used to specify an environment variable which should be set on the remote end.
This allows Git to send additional information when contacting the server, requesting the use of a different protocol version via the 'GIT_PROTOCOL' environment variable like so: "-o SendEnv=GIT_PROTOCOL".

Unfortunately not all ssh variants support the sending of environment variables to the remote end.
To account for this, only use the '-o' option for ssh variants which are OpenSSH compliant.
This is done by checking that the basename of the ssh command is 'ssh' or the ssh variant is overridden to be 'ssh' (via the ssh.variant config).

Other options like '-p' and '-P', which are used to specify a specific port to use, or '-4' and '-6', which are used to indicate that IPV4 or IPV6 addresses should be used, may also not be supported by all ssh variants.

Currently if an ssh command's basename wasn't 'plink' or 'tortoiseplink', Git assumes that the command is an OpenSSH variant.
Since user configured ssh commands may not be OpenSSH compliant, tighten this constraint and assume a variant of 'simple' if the basename of the command doesn't match the variants known to Git.
The new ssh variant 'simple' will only have the host and command to execute ([username@]host command) passed as parameters to the ssh command.

2 of 3
4

Here is the answer:

set GIT_SSH_COMMAND=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no & git push origin master
🌐
EnvManager
envmanager.com › blog › git environment variables: identity, ssh keys, debugging, and ci/cd usage
Git Environment Variables: Identity, SSH Keys, Debugging, and CI/CD Usage - EnvManager
February 16, 2026 - If you've ever juggled multiple GitHub accounts or needed to use a specific SSH key for deployment, GIT_SSH_COMMAND is typically a configure-once setting — until you get a new machine and need to set it up again.
🌐
GitHub
github.com › hashicorp › terraform › issues › 19232
Loading modules via Git, terraform ignores GIT_SSH environment variable · Issue #19232 · hashicorp/terraform
October 31, 2018 - Git configuration (additionally set, but not needed for git clone working properly): git config --global ssh.variant plink
Author: hashicorp
🌐
How-To Geek
howtogeek.com › home › programming › how to fix git using the wrong ssh key & account
How to Fix Git Using the Wrong SSH Key & Account
December 13, 2021 - This is probably the most common Git mistake, and the solution to this is simple---set up an SSH key for your account. But, you can also run into a very similar looking error message, even after having an SSH key set up properly.
🌐
Ek
journal.oye.mlga.ek.gov.ng › home › news › how to specify the private ssh-key to use when executing shell command on git?
How to specify the private SSH-key to use when executing shell command on Git? - Star Vibe
April 17, 2026 - With git 2.10+ (Q3 2016: released Sept. 2d, 2016), you have the possibility to set a config for GIT_SSH_COMMAND (and not just an environment variable as described in Rober Jack Will's answer)
Top answer
1 of 16
1800

None of these solutions worked for me.

Instead, I elaborate on @Martin v. Löwis's mention of setting a config file for SSH.

SSH will look for the user's ~/.ssh/config file. I have mine setup as:

Host gitserv
    Hostname remote.server.com
    IdentityFile ~/.ssh/id_rsa.github
    IdentitiesOnly yes # see NOTES below
    AddKeysToAgent yes

And I add a remote git repository:

git remote add origin git@gitserv:myrepo.git

(or clone a fresh copy of the repo with git@gitserv:myrepo.git as address)

And then git commands work normally for me.

git push -v origin master

If you have submodules, you can also execute the following in the repo directory, to force the submodules to use the same key:

git config url.git@gitserv:.insteadOf https://remote.server.com

NOTES

  • The IdentitiesOnly yes is required to prevent the SSH default behavior of sending the identity file matching the default filename for each protocol. If you have a file named ~/.ssh/id_rsa that will get tried BEFORE your ~/.ssh/id_rsa.github without this option.

  • AddKeysToAgent yes lets you avoid reentering the key passphrase every time.

  • You can also add User git to avoid writing git@ every time.

References

  • Best way to use multiple SSH private keys on one client
  • How could I stop ssh offering a wrong key
2 of 16
1188

Something like this should work (suggested by orip):

ssh-agent bash -c 'ssh-add /somewhere/yourkey; git clone [email protected]:user/project.git'

if you prefer subshells, you could try the following (though it is more fragile):

ssh-agent $(ssh-add /somewhere/yourkey; git clone [email protected]:user/project.git)

Git will invoke SSH which will find its agent by environment variable; this will, in turn, have the key loaded.

Alternatively, setting HOME may also do the trick, provided you are willing to setup a directory that contains only a .ssh directory as HOME; this may either contain an identity.pub, or a config file setting IdentityFile.