2020年6月11日木曜日

Raspberry piからgithubへssh

目的

Raspberry pi 4の8G版を購入した

コードをRaspberry pi上で書こうとは思わないので、メインPCで書いてgithub経由でRPIに届けたい


SSHを有効にする

sudo raspi-config

5 Interfacing Options  Configure connections to peripherals

P2 SSH         Enable/Disable remote command line access to your Pi using SSH

と進んでYesを押すと有効となる

SSHのキーを作成する

ssh-keygen

Githubに登録

下記で出てきたものをgithubの設定のSSH keys New SSH keyに登録

cat id_rsa.pub

Raspberry piのSSH configに登録

生成した秘密鍵(id_rsa)をsshフォルダ(.ssh/github/)に移す

設定ファイルに記載する

pi@raspberrypi:~/Desktop $ cat ~/.ssh/config 
Host github.com
    HostName github.com
    IdentityFile ~/.ssh/github/id_rsa
    User git

確認

ssh github.comと打ち込み問題なくSSH接続することを確認


PTY allocation request failed on channel 0
Hi ****! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

キーの追加

githubに接続する際に暗号化キーのパスワードを毎回聞かれる

ssh-addでキーを登録する

ssh-add ~/.ssh/id_rsa
ssh-add -l

エラーが出た場合

下記のエラーが出ることがあるので下記を打つことで解決される

Could not open a connection to your authentication agent

$ ssh-agent
$ eval `ssh-agent`