1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Permission denied (publickey,gssapi-keyex,gssapi-with-mic). の別解法

Posted at

git cloneをしようとしたら、なにやらエラー出てこけた。

user@ubuntu:/path/to/projects$ git clone ssh://user@{ipaddr}:{port}/path/to/hoge.git
fatal: could not create work tree dir 'hoge': Permission denied

このエラー文の時点で気付くべきだったが、
「よくある秘密鍵の問題か?とりあえずsudoも試しておこう。」とか考えて

user@ubuntu:/path/to/projects$ sudo git clone ssh://user@{ipaddr}:{port}/path/to/hoge.git
Cloning into 'hoge'...
user@{ipaddr}: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

本格的に秘密鍵のエラーが吐き出された。
しかし鍵は作って登録したばかりだし、~/.ssh/configでも問題なく接続できる。
しばらく沼った……。

接続元のディレクトリの所有者が違った

userアカウントにて操作を行っていたが、cloneしたレポジトリを置こうとしてるディレクトリ(カレントディレクトリ)のユーザーがrootになっていた。

user@ubuntu:/path/to/projects$ ls -la
total 16
drwxr-xr-x   4 root root 4096 Oct 16 16:08 ./ # <= ここ
drwxr-xr-x 134 root root 4096 Oct 17 11:07 ../
# cloneしたレポジトリを置きたいディレクトリの所有者を変更する
user@ubuntu:/path/to/projects$ chown user. ./

user@ubuntu:/path/to/projects$ ls -la
total 16
drwxr-xr-x   4 user user 4096 Oct 16 16:08 ./
drwxr-xr-x 134 root root 4096 Oct 17 11:07 ../

cloneに成功

user@ubuntu:/path/to/proijects$ git clone ssh://user@{ipaddr}:{port}/path/to/hoge.git
Cloning into 'hoge'...
remote: Enumerating objects: 2495, done.
remote: Counting objects: 100% (2495/2495), done.
remote: Compressing objects: 100% (1963/1963), done.
remote: Total 2495 (delta 836), reused 1923 (delta 460), pack-reused 0
Receiving objects: 100% (2495/2495), 43.19 MiB | 6.08 MiB/s, done.
Resolving deltas: 100% (836/836), done.

問題はsudoでも秘密鍵でもなかった。

めっちゃ初歩的なミス……

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?