Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@kanon700

RaspberryPi4 ネットワーク編

ネットワーク関係

SSH有効化

$ sudo raspi-config
5 -> P2 SSH -> <yes>
$ mkdir ~/.ssh # フォルダを作っておく

Wifi接続

GUIで初期設定した。
平打PWは怖いので、暗号化したpskを生成して/etc/wpa_supplicant/wpa_supplicant.confに追記
ルートユーザーで以下のコマンドを実行。

$ wpa_passphrase [SSID] [PASS] >> etc/wpa_supplicant/wpa_supplicant.conf

最終的なwpa_supplicant.confは以下。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP

network={
        ssid="[SSID]"
        psk="[暗号化したPASS]"
        key_mgmt=WPA-PSK
}

固定IP

/etc/dhcpcd.conf に以下を追記

interface wlan0
static ip_address=192.168.11.xx
static routers=192.168.11.1
static domain_name_servers=8.8.8.8

公開鍵認証でSSH

1. 接続元PC

$ cd ~/.ssh/
$ ssh-keygen -t rsa -b 4096 -C "xxx@gmail.com"
Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/user/.ssh/id_rsa_rp4
Enter passphrase (empty for no passphrase): # パスワードを入れる
Enter same passphrase again: # もう一度入れる
# ゴニョゴニョ表示されて鍵が生成される
$ scp ~/.ssh/id_rsa_rp4.pub pi@192.168.11.xx:/home/pi/.ssh # SCPで公開鍵をRaspberryPiに転送する

2. RaspberryPi

公開鍵の設定

cd ~/.ssh/
cat id_rsa_rp4.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 ~/.ssh
rm ~/.ssh/id_rsa_rp4.pub

SSHの設定変更
/etc/ssh/sshd_config に以下を追記

Port xxxxx # SSHで使うポート番号
PermitRootLogin no # Rootログインの禁止
AuthorizedkeysFile %h/.ssh/authorized_keys # authに使うファイルの指定
PasswordAuthentication no # パスワード認証の禁止

設定できたらRaspberyPiを再起動する

3. 接続

以下のコマンドでRaspberryPiにログインできたらOK

ssh -i ~/.ssh/id_rsa_rp4 pi@192.168.11.xx -p xxxxx # xxxxxはポート番号
2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kanon700
kanonです! 職業は組み込み系ですが、趣味でPythonやらRaspberryPiやらいじってます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?