How Do I Provide a Username and Password When Running "Git Clone Git@Remote. Git"?
I Know How to Provide a Username and Password to an Https Request Like This: Git Clone but I'd Like to Know How to Provide a Username and Password to the...
I know how to provide a username and password to an HTTPS request like this:
git clone
But I'd like to know how to provide a username and password to the remote like this:
git clone
I've tried like this:
git clone username:password@
git clone git@username:
git clone @username:password
But they haven't worked.
12 Answers
Based on Michael Scharf's comment:
You can leave out the password so that it won't be logged in your Bash history file:
git clone
It will prompt you for your password.
Alternatively, you may use:
git clone
This way worked for me from a GitHub repository.
The user@host:path/to/repo format tells Git to use ssh to log in to host with username user. From git help clone:
An alternative scp-like syntax may also be used with the ssh protocol:
[user@]host.xz:path/to/
The part before the @ is the username, and the authentication method (password, public key, etc.) is determined by ssh, not Git. Git has no way to pass a password to ssh, because ssh might not even use a password depending on the configuration of the remote server.
Must Read
Use ssh-agent to avoid typing passwords all the time
If you don't want to type your ssh password all the time, the typical solution is to generate a public/private key pair, put the public key in your ~/.ssh/authorized_keys file on the remote server, and load your private key into ssh-agent. Also see Configuring Git over SSH to login once, GitHub's help page on ssh key passphrases, gitolite's ssh documentation, and Heroku's ssh keys documentation.