공부/기타 / / 2021. 12. 27. 17:55 Show 비쥬얼 스튜디오 코드로 깃에 업로드 하는법을 배우는 중 오류가 떳다. : Permission denied (publickey). 라는 오류인데, 이건 우리가 SSH Key로 접속해서 사용하는 경우라서 그렇다. PC 에 SSH Key를 등록해주면 해결이 된다. 터미널창(cmd || git bash) 를 열고 ssh-keygen -t rsa -C "본인 Github 계정 이메일주소" 를 입력해주자, 입력을 하고나면 아래 문구가 뜨는데 Enter file in which to save the key (C:\Users\사용자/.ssh/id_rsa): SSH Key 저장 위치를 지정해주는건데, 그냥 엔터를 눌러서 넘어가주자 그 다음 문구로는 아래 문구가 뜨는데 Enter passphrase (empty for no passphrase): 이 문구는 SSH Key의 암호를 입력하는 의미인데, 암호를 입력하기 싫으면 그냥 엔터를 눌러 넘어가자 그 다음 문구로는 아래 문구가 또 뜨는데 Enter same passphrase again: 이 문구는 암호 재확인 문구이다, 비밀번호를 입력한 사람이라면 아까 입력한 비번을 입력하고 아니면 엔터를 눌러 넘어가자 이렇게 입력을 다 맞췄으면 콘솔창에 입력이 됐다는 표시가 뜬다. 그러면 이제 아까 만들었던 키가 저장된 위치로 이동하자 id_rsa.pub 파일을 메모장 같은 프로그램으로 읽어보면, 우리가 만들어둔 키가 있다. 해당 내용을 복사 한 후 > 깃허브 홈페이지 오른쪽 상단 자신의 프로필 이미지를 누른 후, 설정(Settings) 메뉴로 이동해준다. > 그 후, SSH와 GPG 키(SSH and GPG keys) 메뉴를 들어가준다. > 그리고 New SSH key 버튼을 눌러주자 > 그 후 아까 id_rsa.pub 파일에서 복사한 내용을 Key 부분에 입력해주자. (Title 은 입력 안해도 무방) 그렇게 Add SSH Key 를 입력하고 나면 터미널창(cmd || git bash) 를 열고 아래 문구를 입력해 잘 작동하는지 확인해보자 ssh -T Warning: Permanently added the ED25519 host key for IP address 'IP 주소' to the list of known hosts. 이런식으로 뜬다면 정상적으로 된거다, 이제 아까 에러가 뜬 부분을 다시 입력하면 정상적으로 작동하는것을 볼 수 있다. Should the sudo command or elevated privileges be used with Git?You should not be using the sudo command or elevated privileges, such as administrator permissions, with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated. Check that you are connecting to the correct serverTyping is hard, we all know it. Pay attention to what you type; you won't be able to connect to "githib.com" or "guthub.com". In some cases, a corporate network may cause issues resolving the DNS record as well. To make sure you are connecting to the right domain, you can enter the following command: $ ssh -vT > OpenSSH_8.1p1, LibreSSL 2.7.3 > debug1: Reading configuration data /Users/you/.ssh/config > debug1: Reading configuration data /etc/ssh/ssh_config > debug1: /etc/ssh/ssh_config line 47: Applying options for * > debug1: Connecting to github.com port 22.The connection should be made on port 22, unless you're overriding settings to use SSH over HTTPS. Always use the "git" userAll connections, including those for remote URLs, must be made as the "git" user. If you try to connect with your GitHub username, it will fail: $ ssh -T [email protected] > Permission denied (publickey).If your connection failed and you're using a remote URL with your GitHub username, you can change the remote URL to use the "git" user. You should verify your connection by typing: $ ssh -T > Hi username! You've successfully authenticated...Make sure you have a key that is being used
If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.
The ssh-add command should print out a long string of numbers and letters. If it does not print anything, you will need to generate a new SSH key and associate it with GitHub. Tip: On most systems the default private keys (~/.ssh/id_rsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn't need to run ssh-add path/to/key unless you override the file name when you generate a key. Getting more detailsYou can also check that the key is being used by trying to connect to : $ ssh -vT > ... > debug1: identity file /Users/you/.ssh/id_rsa type -1 > debug1: identity file /Users/you/.ssh/id_rsa-cert type -1 > debug1: identity file /Users/you/.ssh/id_dsa type -1 > debug1: identity file /Users/you/.ssh/id_dsa-cert type -1 > ... > debug1: Authentications that can continue: publickey > debug1: Next authentication method: publickey > debug1: Trying private key: /Users/you/.ssh/id_rsa > debug1: Trying private key: /Users/you/.ssh/id_dsa > debug1: No more authentication methods to try. > Permission denied (publickey).In that example, we did not have any keys for SSH to use. The "-1" at the end of the "identity file" lines means SSH couldn't find a file to use. Later on, the "Trying private key" lines also indicate that no file was found. If a file existed, those lines would be "1" and "Offering public key", respectively: Verify the public key is attached to your accountYou must provide your public key to GitHub to establish a secure connection.
If you don't see your public key in GitHub, you'll need to add your SSH key to GitHub to associate it with your computer. Warning: If you see an SSH key you're not familiar with on GitHub, delete it immediately and contact GitHub Support, for further help. An unidentified public key may indicate a possible security concern. For more information, see "Reviewing your SSH keys." |