program tip

Gitlab에서 권한 거부 (공개 키) 받기

radiobox 2020. 9. 15. 07:43
반응형

Gitlab에서 권한 거부 (공개 키) 받기


내 문제는 GitLab에서 푸시하거나 가져올 수 없다는 것입니다. 그러나 복제 할 수 있습니다 (HTTP 또는 SSH를 통해). 푸시하려고 할 때이 오류가 발생합니다.

권한 거부 됨 (공개 키) 치명적 : 원격 저장소에서 읽을 수 없습니다.

내가 본 모든 스레드에서 내가 한 일은 다음과 같습니다.

  • 내 컴퓨터에 SSH 키를 설정하고 GitLab에 공개 키를 추가했습니다.
  • 사용자 이름 및 이메일에 대한 config --global을 완료했습니다.
  • 문제가 해결되는지 확인하기 위해 SSH 및 HTTP를 통해 복제 됨
  • ssh -T git@gitlab.com 명령을 완료하십시오.

내 문제를 해결하는 방법에 대한 통찰력이 있으면 크게 감사하겠습니다.


나는 많이 검색 한 후에 이것을 발견했습니다. 그것은 나를 위해 완벽하게 잘 작동합니다.

  1. cmd처럼 "Git Bash"로 이동합니다. 마우스 오른쪽 버튼을 클릭하고 "관리자 권한으로 실행".
  2. 유형 ssh-keygen
  3. 엔터 키를 치시오.
  4. 특정 디렉토리에 키를 저장하라는 메시지가 표시됩니다.
  5. 엔터 키를 치시오. 암호를 입력하거나 암호없이 입력하라는 메시지가 표시됩니다.
  6. 공개 키는 특정 디렉토리에 생성됩니다.
  7. 이제 디렉토리로 이동하여 .ssh폴더를 엽니 다 .
  8. 파일이 표시됩니다 id_rsa.pub. 메모장에서 엽니 다. 모든 텍스트를 복사하십시오.
  9. https://gitlab.com/profile/keys로 이동합니다 .
  10. 여기에 "키"텍스트 필드를 붙여 넣습니다.
  11. 이제 아래의 "제목"을 클릭하십시오. 자동으로 채워집니다.
  12. 그런 다음 "키 추가"를 클릭합니다.

이제 한번 시도하면 확실히 작동합니다.


1 단계 : ~ / .ssh / 폴더에 다음과 같은 구성 파일 추가

   User git
   Hostname gitlab.com
   IdentityFile ~/.ssh/id_rsa_gitlab
   TCPKeepAlive yes
   IdentitiesOnly yes

2 단계 : sudo없이 git repo를 복제하십시오.


간단한 해결책은 인증 에이전트에 개인 키를 추가하는 것입니다 (키가 아닌 경우 ~/.ssh/id_rsa).

ssh-add ~/.ssh/<your private key>

당신은 기본적으로 ssh-agent그것을 처리합니다.

또한 영구적으로 추가 할 수 있습니다 .


실행 중이 아닌지 확인하십시오 sudo git clone git@gitlab.com:project/somethiing.git. 그렇지 않으면 /root/.ssh업로드 한 키 대신 ssh가 검색됩니다.~/.ssh/id_rsa


제 경우에는 WSL (Linux 용 Windows 하위 시스템)에서 작동하지 않았습니다.

WSL을 시작할 때

  • ssh-agent_ 시작 eval $(ssh-agent -s)
  • ssh-agent에 키를 추가합니다. ssh-add ~/.ssh/id_rsa
  • 메시지가 나타나면 암호를 입력하십시오

이제 연결이 작동합니다.
우리는 이것을 테스트 할 수 있습니다.ssh -T git@github.com

노트:


In my case, it wasn't a gitlab problem, but a sshd configuration one. The ssh server didn't allow connection except for a list of users. The user git, the one connecting remotely to gitlab, wasn't in that list. So, check this before anything else.

You can check your ssh server configuration in /etc/ssh/sshd_config. If you have a line with the option AllowUsers, add git to it:

AllowUsers user1 user2 user3 git

if you are in Linux or macox , just try this in terminal:

ssh-add -l

if it return nothing, try this:

ssh-add

it must create identity in ~/.ssh/id_rsa

after retry :

ssh-add -l

it must return your identity, so after retry to clone, it's must work

NB: don't forget to add your ssh key in your profile gitlab

thanks


I had the same issue, I resolved it by adding a new ssh key:

  1. ssh-keygen -t ed25519 -C "email@example.com"
  2. Copy your public SSH key to the clipboard (xclip -sel clip < ~/.ssh/id_ed25519.pub in my case on Linux )
  3. On gitlab, go to settings=>ssh keys and past the new key

I have gitlab running with docker, this is what I did to fix my problem.

Found that inside docker /var/log/gitlab/sshd/current there were multiple occurences of a message:

Authentication refused: bad ownership or modes for file /var/opt/gitlab/.ssh/authorized_keys

After which I changed ownership of that file from 99:users to git:users with:

chown git:users authorized_keys


Steps to be done, got same error but i fixed it. Gitlab wants ssh-rsa so below is the code to run ssh for rsa

  1. ssh-keygen -o -t rsa -b 4096 -C "name@gmail.com"

name@gmail.com is your gitlab account email

  1. It will prompt you to enter so just hit Enter after the below code is prompt,

    Enter file in which to save the key (/home/yourDesktopName/.ssh/id_rsa):

  2. It will prompt again you to enter so just hit Enter after the below code is prompt,

    Enter passphrase (empty for no passphrase):

  3. It will prompt again for the last you to enter so just hit Enter after the below code is prompt,

    Enter same passphrase again:

  4. You will show your ssh-rsa generate.

  5. Login to your Gitlab account and Go to the right navbar you will get setting and in the left sidebar you will get ssh key. Enter in it.

  6. Look above the prompt asking you to enter, you will get the path of ssh-rsa.

  7. Go to your SSH folder and get the id_rsa.pub

  8. Open it and get the key and Copy Paste to the Gitlab and you are nearly to done.

  9. Check by: ssh -T git@gitlab.com

  10. You will get: Welcome to GitLab, @joy4!

  11. Done.


When you have multiple git account and you want different ssh key

You have to follow same step for generating the ssh key, but be sure you

ssh-keygen -t ed25519 -C "your-email-id@gmail.com" 

Enter the path you want to save(Ex: my-pc/Desktop/.ssh/ed25519)

Add the public key to your gitlab (How to adding ssh key to gitlab)

You have to new ssh identity using the below comand

ssh-add ~/my-pc/Desktop/.ssh/ed25519

Two things mainly

  1. You must have id_rsa.pub and id_rsa (private) keys in your .ssh folder ( which should be in your home folder.Create it if it isn't there put your keys ). It wouldn't work If you have named your key files differently

  2. Change the permission of the id_rsa as chmod 400 ~/.ssh/id_rsa


Go to the terminal and regenerate the ssh key again. Type ssh-keygen. It will ask you where you want to save it, type the path.

Then copy the public key to gitlabs platform. It usually starts with ssh-rsa.


I found the solution in gitlab help.

To create a new SSH key pair: 
 1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
 2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
 2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
 3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
 4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
 5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
        macOS:        pbcopy < ~/.ssh/id_ed25519.pub
        WSL / GNU/Linux (requires the xclip package):      xclip -sel clip < ~/.ssh/id_ed25519.pub
        Git Bash on Windows:      cat ~/.ssh/id_ed25519.pub | clip
 6. Navigating to SSH Keys and pasting your public key in the Key field
 7. Click the Add key button

I hope it can help some of you!


Another issue that can cause this behaviour is when you have a setup with 2 possible %HOME%-locations.

I'm using a PC where some of my documents are stored locally, and some of them are stored on a network drive. Some applications think C:\Users\<MyUserName>\ is my %home%, others think that U:\ is the home.

Turns out ssh-keygen put my private key under C:\users\<MyUserName>\, and that ssh -T and ssh -v also look there.

So everything seems to work fine, except that git clone, git push and others look for a key in U:\. Which fails, so I get the aforementioned error.

It took me an hour to find out, but in the end the solution was simple: I copied everything from C:\Users\<MyUserName>\.ssh to U:\.ssh


How to add SSH key to gitlab account in ubuntu?

  1. Open terminal in your project directory.
  2. Type ‘ssh-keygen -o -t rsa -b 4096 -C "your gitlab email" ’ and hit enter
  3. Type ‘vim /home/mnbtech/.ssh/id_rsa.pub’ and hit enter (or manually open your 'id_rsa.pub'from where you saved it)
  4. SSH key will appear. Copy those and

  5. Go to your gitlab account.

  6. Click profile image And click setting
  7. In left side select SSH-Keys
  8. Then paste those key Click add key

SSH-Key will be added!

(N.B if you have Generate Previews SSH Key and Getting permission denied (public key). You Delete Your Previews ssh key and Generate new one and add git user.name and email on your terminal )


Earlier it was very difficult for me but when I tried it became so easy to add ssh key in Mac and Linux. There are a few steps and command to do this as follows:

  1. Open a terminal of your system and move inside your project directory by the command:
cd 'project directory name'
  1. Run command ssh-keygen in that terminal and enter it until the key's randomart image appears there.

  2. Then enter one more command in that terminal:

cat ~/.ssh/id_rsa.pub

It will generate your ssh key. Key will start with ssh-rsa and end with .local.

  1. Copy the key and go to your Gitlab profile section then ssh key section and paste it there. Click on the Add button this will work.

I solved like this..

Generated a key for Windows using this command:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

but the problem was that after running this command, it popped a line: "Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa): " Here, I was giving only file name because of which my key was getting saved in my pwd and not in the given location. When I did "git clone ", it was assuming the key to be at "/c/Users/xxx/.ssh/id_rsa" location but it was not found, hence it was throwing error.

At the time of key generation 2 files were generated say "file1" & "file1.pub". I renamed both these files as

file1 -> id_rsa 

and

file1.pub -> id_rsa.pub

and placed both in the location "/c/Users/xxx/.ssh/"


I added my ~/.ssh/id_rsa.pub to the list of known SSH Keys in my GitLab settings https://gitlab.com/profile/keys. That solved the problem for me. :-)


I use ubuntu 18.04, and it was actually permission issue in my local machine. The issue was gone when I set read/write permission to my .git folder.


Well I had this same problem and after trying the answer @Khan proposed. However, I was only able to make it work by just changing the origin url in the .git/config file to the https address : https://gitlab.com/mygitlabusername/mygitproject.git

Since access via ssh is denied, I figured out using https shouldn't be a problem. It will however ask for your username and password for each push to the at repository


The problem for me was, that I switched UsePAM from yes to no in the SSH configuration file under /etc/ssh/sshd_config. With UsePAM yes everything works perfectly.


Please use git config credential.helper store if your site is using TLS/SSL. Hope this works


There seem to be differences between the two ways to access a git repository i.e. using either SSH or HTTPS. For me, I encountered the error because I was trying to push my local repository using SSH.

The problem can simply be solved by clicking the clone button on the landing page of your project and the copying the HTTPS link and replacing it to the SSH link appearing with the format "git@gitlab...".


There is a very simple solution to this: instead of working with ssh - move to https. to do this: in your project folder you have a .git folder in there - you have a config file - open it in a text editor and change the line

url =git@gitlab.com:yourname/yourproject.git

to

url = https://gitlab.com/yourname/yourproject.git


Change permission :: chmod 400 ~/.ssh/id_rsa It helped for me.

참고URL : https://stackoverflow.com/questions/40427498/getting-permission-denied-public-key-on-gitlab

반응형