SSH Key - Still asking for password and passphrase
If you work with HTTPs
urls, it'll always ask for your username / password. This could be solved using @Manavalan Gajapathy's comment (copying here):
See this github doc to convert remote's URL from https to ssh. To check if remote's URL is ssh or https, use git remote -v
. To switch from https to ssh:
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
If you're correctly using SSH
when cloning / setting remotes: make sure you have a ssh-agent to remember your password (see this answer by @Komu). That way, you'll only enter your passphrase once by terminal session.
If it is still too annoying, then simply set a ssh-key without passphrase.
SSH GitLab pull always asks for password
Your ssh key is generated with a passphrase and that's why it asks you for the passphrase.
SSH login without password
Your aim
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
How to do it
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase: (THIS IS THE CATCH, just press enter here to leave it empty):
Enter same passphrase again: (press enter again)
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
a@A:~> ssh-copy-id remote_username@remote_domain
or
a@A:~> ssh-copy-id remote_username@remote_IP
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote_username@remote_domain password:
There it will ask you to enter the password for the remote user on that remote server
Number of key(s) added: 1
Now try logging into the machine, with: "ssh -p '22' 'remote_username@remote_domain'"
and check to make sure that only the key(s) you wanted were added.
Now try to login with
a@A:~> ssh remote_username@remote_domain
and you should get in
Source: http://www.linuxproblem.org/art_9.html
Gitlab ignores ssh key after my own OS was reinstalled
Fixed by appending own rsa key to the end of authorized_keys file of host's 'git' user.
After adding public key to gitlab still cli want login and password
You need to change the remote URL of your origin:
git remote set-url origin <your ssh url>
Or just clone it again with the SSH URL shown on the GitLab project page.
Cannot access gitlab repo using ssh keys using Windows
I get a popup asking for my gitlab username and password which I enter and which fails.
Check, as commented:
git remote -v
git config credential.helper
If the first starts with https://
, and the second is not empty, what you see is a Git credential helper trying to cache your HTTPS credentials.
That means your SSH key would be ignored anyway.
Regarding the error message, check out this thread, and test it with:
ssh -o UpdateHostKeys=no -Tv git@gitlab.com
To make it persistent, in ~/.ssh/config
:
Host gitlab.com
UpdateHostKeys no
GitLab cloning via SSH always prompts for password
As the server is running CentOS with SELinux, policys might have to be adjusted.
First test if SELinux might be the issue by running the following on the server
sudo setenforce 0
If you are able to use public/private key pairs with setenforce 0
re-enable SELinux with
sudo setenforce 1
Solution if SELinux stops cloning by using public/private key pairs
Provided that /var/opt/gitlab/ is your gitlab installation git user's home folder run the following
sudo semanage fcontext -a -t ssh_home_t /data/gitlab/.ssh/
sudo semanage fcontext -a -t ssh_home_t /data/gitlab/.ssh/authorized_keys
sudo restorecon -Rv /data/gitlab/
The file /var/opt/gitlab/gitlab-shell/config.yml
will also be access and thus needs to have its context edited
sudo semanage fcontext -a -t ssh_home_t /data/gitlab/gitlab-shell/config.yml
sudo restorecon -Rv /data/gitlab/gitlab-shell/
as well as /data/gitlab/gitlab-rails/etc/gitlab_shell_secret
sudo semanage fcontext -a -t ssh_home_t /data/gitlab/gitlab-rails/etc/gitlab_shell_secret
sudo restorecon -Rv /data/gitlab/gitlab-rails
Confirm that the context changes have been applied by running
sudo semanage fcontext --list
You should see
/data/gitlab/.ssh/authorized_keys all files system_u:object_r:ssh_home_t:s0
/data/gitlab/.ssh/ all files system_u:object_r:ssh_home_t:s0
/data/gitlab/gitlab-shell/config.yml all files system_u:object_r:ssh_home_t:s0
/data/gitlab/gitlab-rails/etc/gitlab_shell_secret all files system_u:object_r:ssh_home_t:s0
If that is the case try to clone from your repository. For details refer to lemoncodes support thread on gitlab.com
How to clone private group's GitLab repository without typing password?
It appears that according to this answer you could choose between two types of urls
- either with schema,
ssh://git@gitlab.com/group/repo.git
in this case - or "scp-like", without schema,
git@gitlab.com:group/repo.git
(example from gitlab docs)
You have to choose only one of them and mixing them will most likely lead to problems (that's what happened with ssh urls at question).
Also note that if you prefer scp-like urls AND you have to specify port you probably want to put port into .ssh/config
file instead of url, like this (I personally failed to figure out correct port placement directly in url but config file worked without issues).
Related Topics
How to Add a System Call via a Lkm
R Programming - Submitting Jobs on a Multiple Node Linux Cluster Using Pbs
Linux Kernel: Copy_From_User - Struct with Pointers
Bash: How to Perform Arithmetic on Numbers in a Pipe
How to Get Around the Linux "Too Many Arguments" Limit
Dotnetcore: Cross Platform Version of Getinvalidfilenamechars
Replace Line with Space and Backslash with a String Containing Spaces
One-Liner: Print All Lines Except the Last 3
Linux Perf Record: Difference Between Count (-C) and Frequency (-F) Options
Compile Git for 32-Bit Linux on Shared Hosting
Why Do I Get /Etc/Cups Conflicts Between Attempted Installs in Yocto
Run Shell Command and Don't Wait for Return
Setting Environment Variable to a Large Value -> "Argument List Too Long"
How to Merge Two Rows in a Same Row from a Text File in Linux Shell Script