Dear StackOverflow community,
I created ssh-keys following this (https://gitlab.com/help/ssh/README) instruction. I added the ED25519 SSH key pair to the GitLab profile on the webpage and if I do ssh -T git#gitlab.com I do obtain the message Welcome to GitLab, #username!, so that far it seems to work.
However, I want to git push and git pull from my local repository to GitLab without typing my password every time. As far as I understand the SSH-keys, that should be exactly the thing they do, right?
EDIT:
my .ssh/config contains:
Host machine
User username
HostName machine.webside.com
The .gitconfig contains:
[user]
name = John Doe
email = john.doe#email.com
and the .git/config contains:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://gitlab.com/johndoe/projectname.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "branch1"]
remote = origin
merge = refs/heads/branch1
[branch "branch2"]
remote = origin
merge = refs/heads/branch2
Your .git/config shows that your repository is accessed over HTTPS, therefore using username and password authentication.
If you want to switch to ssh, you also have to change your local GIT configuration, in addition to adding an SSH key.
GitHub has a very detailed tutorial about changing your GIT remote URL from a HTTPS to a SSH one: https://help.github.com/en/articles/changing-a-remotes-url#switching-remote-urls-from-https-to-ssh
The steps described there are also applicable for GitLab, except that your remote URL will be something like git#gitlab.com:<repo-url.git> instead of git#github.com:<repo-url>.git
More or less, you just have to use git remote set-url origin.
Related
I have generated an id_ed25519 key on my server and set it in Gitlab, when I try to connect with SSH, I get the welcome message, but when using git pull, it's still requiring credentials (username and password).
$ ssh -T git#gitlab.com
Welcome to GitLab, #john.doe!
$ git pull
Username for 'https://gitlab.com': john.doe
Password for 'https://john.doe#gitlab.com':
Already up to date.
What's missing in my configuration ?
I guess it would be because you are using https git remote url instead of ssh one.
Please check your configured remote, it should be the https one:
$ git remote -v
origin https://gitlab.com/john.doe/myproject.git (fetch)
origin https://gitlab.com/john.doe/myproject.git (push)
You'll want to change it to the SSH one:
$ git remote set-url origin git#gitlab.com:john.doe/myproject.git
This does what OP mentioned in the comment of the accepted answer, without having to manually edit the config file. Please upvote the accepted answer before mine :)
I have been running gitolite for some time and this week set up a second server as a mirror for all of my repositories.
I have the following stanzas in the gitolite.conf file that has been pushed to both servers:
repo data/[0-9]+/..*
C = #developers
RW+ = #developers
R = #all
option mirror.master = oxygen
option mirror.slaves = nitrogen
repo mirror_test
RW+ = #all
option mirror.master = oxygen
option mirror.slaves = nitrogen
I have repos of the names "data/11756/machine11756.git", "data/11756/recorded11756.git", and "data/11779/machine11779.git", over 70 in total.
After setting up mirroring and testing it via the mirror_test repo. I needed to get copies of the repos onto the slave, so I then wrote a script to run "ssh gitolite mirror push nitrogen ". Only nine of these mirror pushes succeeded, the remaining ones returned:
fatal: '/home/git/repositories/data/11756/machine11756.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What is going on?
The syntax for Gitolite mirroring should be:
ssh git#host mirror push slave-server-name repo-name
In your case, gitolite can be an entry in ~/.ssh/config.
Beside a possible SSH syntax issue, it would come done to an access or permission issue on the remote side.
I was new to Gitlab was trying to push my project from local machine to Gitlab.
Have done the SSH key and followed the instructions at Gitlab. Done the Git global setup. Was trying to add an existing folder , so i followed the instructions listed
cd existing_folder
git init
git remote add origin https://gitlab.com/sss/testnode.git
git add .
git commit -m "Initial commit"
git push -u origin master
but failed at the last step at the git push. The error message was
Tried adding the remote origin, but it was told it already exists. So not sure where it went wrong. Please help, much appreciated :)
Have done the SSH key
The problem is that you have defined your origin as HTTPS, not SSH.
Try:
git remote set-url origin git#gitlab.com:sss/testnode.git
That will override origin URL.
Independently, make sure your SSH key does work and allows GitLab to authenticate you as your GitLab account with:
ssh -T git#gitlab.com
Check out your credentials, if they are invalid, it wont give u to upload changes.
For Windows check this: https://www.digitalcitizen.life/credential-manager-where-windows-stores-passwords-other-login-details
For Linux check this: https://askubuntu.com/questions/30907/password-management-applications (if you do not know how to change credentials via terminal)
I have two repositories on one machine on the same account on Github. I've added an ssh key to my account and pushing to repository A succeeds but I can't push to repository B. SSH keys on github aren't associated to specific repos iirc.
A little research has led me to find out that I need two different keys. How do I edit my config file so that git uses the correct key when pushing to the second repo?
I got to the solution by modifying the .ssh/config file to append this
Host repo2.github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_rsa2
TCPKeepAlive yes
IdentitiesOnly yes
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
and then adding by appending the following in the .git/config file
[remote "origin"]
url = git#repo2.github.com:[Username]/G2-FrontEnd.git
fetch = +refs/heads/*:refs/remotes/origin/*
Yesterday started having weird issues with my github repos, when was suddenly prompted for user & passwd for push. Git is set up using ssh, and no changes have been made in months.
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
$ cat .git/config
/-/
[remote "origin"]
url = git#github.com:user/repo.git
/-/
$ git config remote.origin.url
git#github.com:user/repo.git
Re-setting via remote set-url doesn't change anything either.
No issues with bitbucket repos. Has there been some change I've missed?
My gitconfig includes a config from one of the projects I'm currently working on. A new property was introduced I wasn't aware of:
[url "https://github.com/"]
insteadOf = "git://github.com/"
Case closed.