Zeshan
Zeshan

Reputation: 2657

How to avoid typing Git password on every push/pull in OS X

I'm using Git for pushing my changes to staging server (not GitHub). Whenever I use to push or pull, I need to enter remote server's (staging) password. Is there any way to save the credentials on my local machine and avoid typing password every time?

My remote origins are:

origin [email protected]:/opt/git/xxx.git (fetch)

origin [email protected]:/opt/git/xxx.git (push)

Upvotes: 1

Views: 403

Answers (2)

Dr Manhattan
Dr Manhattan

Reputation: 14037

Turn on the credential helper so that Git will save your password in memory for some time. by default git will remember it for 15min, but you can change that, do the following:

In Terminal, enter the following:

git config --global credential.helper cache

# Set git to use the credential memory cache

To change the default password cache timeout, enter the following:

git config --global credential.helper 'cache --timeout=3600'

# Set the cache to timeout after 1 hour (setting is in seconds, you can chnage it to 24hours = 86400 seconds if you like)

If you set it to 24hrs you only have to enter your password once a day ,jusy like logging into your email account in the morning :)

source: link

Upvotes: 0

Ryan
Ryan

Reputation: 14649

This will create two files. id_rsa and id_rsa.pub Put the public key on your server.

ssh-keygen -t rsa

Put the public key on your server make sure the permissions on authorized_keys is 0600

Append the public key to the .ssh/authorized_keys file which exists in the home directory of the user your are pushing to the server as.

Unless your pushing as the root user, you will most likely run into problems with your current setup. Is /opt/git owned by your git user?

Does git have a home directory? It is best to push to your remote server as a user with a home directory on that server because that makes SSH access easier.

Upvotes: 3

Related Questions