クラウドドライブにgitのリモートリポジトリを構築する
そもそもクラウド自体がgit(だと思う)を使って実現しているわけだから,いかにも屋上屋を架している感があるが,メリットがないわけではない.
こういう場合に
やったこと
mac osxの場合(ほかはわからない)
gitのユーザー名とメールアドレスを設定(一度もgitを使ったことがない場合)
$ git config --global user.name "username" $ git config --global user.email "user@email.com"
リモートリポジトリを作る
pushする先になるディレクトリをDropboxなどの適当な場所に作る.
末尾を ".git" にするのが慣習らしい.
ディレクトリを作ったら,gitをリモートとして(--bareオプション)初期化する.
$ mkdir ~/Dropbox/myrepo.git $ git --bare init --shared
公開鍵認証の設定
今回ほとんど唯一と言っていい,はまった箇所.
公開鍵暗号を設定すると,いちいちコマンドを打つたびにパスワードを聞かれるということがなくなる.
...はずなのだが,この公開鍵認証が一向に成功せず,パスワードを聞かれ続け,
やっと聞かれなくなったと思ったら認証が通らない状態になった.
こんな感じのエラーが出て,
username@localhost: Permission denied (publickey,password). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
$ ssh -v localhost
でデバッグモードで接続してログを詳細表示すると,
OpenSSH_7.9p1, OpenSSL 1.0.2q 20 Nov 2018 debug1: Reading configuration data /usr/local/etc/ssh/ssh_config debug1: Connecting to localhost [::1] port 22. debug1: Connection established. debug1: identity file /Users/username/.ssh/id_rsa type 0 debug1: identity file /Users/username/.ssh/id_rsa-cert type -1 debug1: identity file /Users/username/.ssh/id_dsa type -1 debug1: identity file /Users/username/.ssh/id_dsa-cert type -1 debug1: identity file /Users/username/.ssh/id_ecdsa type -1 debug1: identity file /Users/username/.ssh/id_ecdsa-cert type -1 debug1: identity file /Users/username/.ssh/id_ed25519 type -1 debug1: identity file /Users/username/.ssh/id_ed25519-cert type -1 debug1: identity file /Users/username/.ssh/id_xmss type -1 debug1: identity file /Users/username/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.9 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.9 debug1: match: OpenSSH_6.9 pat OpenSSH* compat 0x04000000 debug1: Authenticating to localhost:22 as 'username' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256@libssh.org debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC:compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:(なんらかの鍵) debug1: Host 'localhost' is known and matches the ECDSA host key. debug1: Found key in /Users/username/.ssh/known_hosts:2 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks debug1: Will attempt key: /Users/username/.ssh/id_rsa RSA SHA256:(公開鍵) debug1: Will attempt key: /Users/username/.ssh/id_dsa debug1: Will attempt key: /Users/username/.ssh/id_ecdsa debug1: Will attempt key: /Users/username/.ssh/id_ed25519 debug1: Will attempt key: /Users/username/.ssh/id_xmss debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Offering public key: /Users/username/.ssh/id_rsa RSA SHA256:(公開鍵) debug1: Authentications that can continue: publickey debug1: Trying private key: /Users/username/.ssh/id_dsa debug1: Trying private key: /Users/username/.ssh/id_ecdsa debug1: Trying private key: /Users/username/.ssh/id_ed25519 debug1: Trying private key: /Users/username/.ssh/id_xmss debug1: No more authentication methods to try. username@localhost: Permission denied (publickey).
実際には,ちょっとずつ設定をいじるたびにちょっとずつ内容が変わるが,
だいたい最後のところでパスワードを認証に使うかどうかというところが違うくらい.
やったこと
公開鍵と秘密鍵のペアを作る
$ ssh-keygen # いろいろ聞かれるが,基本的にデフォルトのままenterでOK # id_rsaとid_rsa.pubが生成される $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys # 要するに名前を変えてコピーしてるだけ # とんでもない間違いに気づいたので修正…