Gitlab: How to git pull without credentials? - gitlab

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 :)

Related

Pushing to git with Personal Access Token is asking for password

I have a shell script file which will push the files to empty git repo.
git init
git add .
git commit -m "first commit"
git remote add origin https://<my-personal-access-token>#github.com/<organization-name>/<repo-name>.git
git push -u origin master
This was pushing files to repo without asking for password, but surprisingly now it is asking for password too.
Why is it asking for password even though I used personal access token? What is going wrong here?
Even if I input correct password manually, it says as below :
You can try below line in your code for git remote step by adding username to it:
git remote add origin https://username:<my-personal-access-token>#github.com/<organization-name>/<repo-name>.git

Gitlab pushing first project failed due to could not read from remote repository

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)

Cannot push to my github private repository

As I'm learning git, I have set up a private repository on GitHub. I have created ssh key and store it to my GitHub account and edited .ssh/config file on my local Linux machine:
## github
Host github.com
User git
HostName github.com
IdentityFile ~/.ssh/github.key
I can successfully connect to my GitHub account:
$ ssh -T github
Hi <UserName>! You've successfully authenticated, but GitHub does not provide shell access.
I have initialized a git repository on my local machine, set up user and added a remote repository:
$ git init
$ git config user.name "UserName"
$ git config user.email "UserEmail"
$ git remote add origin ssh://github:<UserName?/<repositoryName>.git
I have created a README.md file, added it to git and commited it:
$ git add README.md
$ git commit -m "First commit."
Now everytime I try to push, I get this error:
$ git push origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Cloning the repository works, however that is the only thing I can do.
Why can't I push to my private repository? What am I doing wrong?
Try instead the scp syntax, to make sure your ~/.ssh/config file is used:
git remote set-url origin github:<username>/<repo>
Then try and push again.
Git itself uses an OpenSSH version (at least the one packages with Git for Windows)
> ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2k 26 Jan 2017
As explained in "Why doesn't the ssh command follow RFC on URI?", there is a difference between:
ssh://[user#]host.xz[:port]/path/to/repo.git
vs.
user#host.xz:/path/to/repo.git
Only the latter syntax user#host.xz: uses the ssh config file.
When SSH was originally developed, it was developed as a more secure, drop-in replacement for the earlier RSH/rlogin suite of tools.
See "History of the SSH protocol".
OpenSSH (1999) predates URI (finalized in RFC 3986, published in January 2005)
If the host portion was allowed to be on the form host:port, this would create a potential ambiguity: does jdoe#host.example.com:2222 refer to ~jdoe/2222 on host.example.com when connecting on the standard port, or does it refer to no file at all (or worse, ~jdoe) on host.example.com when connecting over port 2222?

Git requires username and password for git push, git pull using HTTPS method

So, when I use HTTPS method for cloning git repository and do some changes and push or pull to git it will always be prompting me for username and password. what's the solution for that?
Apart from changing to SSH, you can also keep using HTTPS, if you don't mind to put your password in clear text. Put this in your ~/.netrc and it won't ask for your username/password (at least on Linux and Mac)
Make one .netrc file in your home directory.
machine github.com
login <user>
password <password
The solution to your problem is this git command which is kind of remember me of GIT.
git config credential.helper store
Read this for details:
GIT credentials store

How to skip password typing for Git against Kerberos?

I have a problem with git clone from TFS. Client is Ubuntu 14.04,
TFS certificates are available because https works properly. Proxy is unset in Git and global env.
Working scenarios:
A. git clone https://url.to.my.tfs/
B. git clone https://user#url.to.my.tfs/
A. requests username and password, type them, all proceed good.
B. Git don't request a password. Cloning is proceed good. So communication linux(git)-kerberos(TFS) is already OK.
Modified A.) pressed Enter when git request for username and password I get:
fatal: Authentication failed for https://url.to.my.tfs
So, where is the problem? How to skip password typing?
fatal: Authentication failed for... is exactly because of that you didn't type user/pass when requested.
And git clone https://user#url.to.my.tfs/ and no password requests from Git can be because of Git credential.helper cache used on HTTPS protocols.
https://git-scm.com/book/gr/v2/Git-Tools-Credential-Storage
This answered question relates to HTTPS on Github but it also applies to your scenario. Is there a way to skip password typing when using https:// on GitHub?
There you can find option that suits you best.

Resources