各サーバーに、共通となる基本的なセットアップ内容をメモっていますが、あくまでも個人的な内容となるので、ご参考までに。
最近は、Raspberry Pi OSを中心としたシステム構成になっていて、このサイトでも利用しています。
今後、随時更新されていくと思います。
初回電源投入
初回の電源投入時に、MicroSDカードが使用可能な容量まで、自動的に拡張してくれます。
画面には、青バックで「Resized root filesystem. Rebooting in 5 seconds …」と、一瞬ですが表示されると思います。
無線LANの有効化
無線LANが無効状態なので、無線LANが使えるようにします。
Raspbian GNU/Linx 10 raspberrypi tty1 raspberrypi login: pi ← インストール直後のユーザー名 Password: raspberry ← インストール直後のパスワード Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Wi-Fi is currently blocked by rfkill. Use raspi-config to set the country before use. pi@raspberrypi:~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf ← 設定前のファイル内容 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 pi@raspberrypi:~ $ sudo raspi-config nonint do_wifi_country JP OK pi@raspberrypi:~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf ← 設定後のファイル内容 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=JP ← 追加された pi@raspberrypi:~ $ sudo systemctl reboot
無線LANで接続をするための設定を行ないます。
Raspbian GNU/Linx 10 raspberrypi tty1 raspberrypi login: pi Password: raspberry Last login: Thu Feb 13 16:17:09 GMT 2020 on tty1 Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. pi@raspberrypi:~ $ iwconfig wlan0 ← 無線LANの設定参照 wlan0 IEEE 802.11 ESSID:off/any Mode:Managed Access Point: Not-Associated Tx-Power=31 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on pi@raspberrypi:~ $ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=JP network={ ssid="xxxxx" ← 利用する無線アクセスポイントのSSIDを設定 psk="xxxxx" ← 利用する無線アクセスポイントの事前共通鍵を設定 } pi@raspberrypi:~ $ sudo raspi-config nonint get_ssh ← 設定前の状態を参照 1 pi@raspberrypi:~ $ sudo raspi-config nonint do_ssh 0 ← sshでログインできるように変更 pi@raspberrypi:~ $ sudo raspi-config nonint get_ssh ← 設定後の状態を参照 0 pi@raspberrypi:~ $ sudo systemctl reboot
Teratermなど適当なターミナルからsshでログインができるかを確認します。接続先のIPアドレスは、DHCPサーバで振られているIPアドレスを確認してください。
ユーザー名 : pi
パスワード:raspberry
Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. pi@raspberrypi:~ $ iwconfig wlan0 wlan0 IEEE 802.11 ESSID:"xxxxx" Mode:Managed Frequency:2.422 GHz Access Point: xx:xx:xx:xx:xx:xx Bit Rate=150 Mb/s Tx-Power=31 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on Link Quality=64/70 Signal level=-46 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:1066 Invalid misc:0 Missed beacon:0
パッケージの更新
パッケージを更新して、最新のものを使うようにします。
pi@raspberrypi:~$ sudo apt update ← パッケージリストのデータベースを更新 : (割愛) pi@raspberrypi:~$ sudo apt upgrade ← インストール済パッケージの更新 : (割愛) The following package was automatically installed and is no longer required: rpi-eeprom-images Use 'sudo apt autoremove' to remove it. The following packages will be upgraded: : (割愛) Do you want to continue? [Y/n] Y : (割愛) pi@raspberrypi:~$ sudo apt autoremove ← いらなくなったパッケージの自動削除 : (割愛) The following packages will be REMOVED: rpi-eeprom-images : (割愛) Do you want to continue? [Y/n]Y : (割愛) pi@raspberrypi:~ $ sudo systemctl reboot
デフォルトのユーザー名とパスワードの変更
デフォルトのユーザー名「pi」とパスワード「raspberry」のままでは、セキュリティー的に良くないので変更します。
まずは、仮のユーザーを作成します。「pi」ユーザーでログインしている状態では、「pi」ユーザー自身の変更できないためです。
ユーザー名 : pi
パスワード : raspberry
Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. pi@raspberrypi:~ $ sudo useradd -M tmpuser ← 「-M」でホームディレクトリーを作成しない pi@raspberrypi:~ $ sudo gpasswd -a tmpuser sudo ← sudoグループに追加 Adding user tmpuser to group sudo pi@raspberrypi:~ $ sudo passwd tmpuser New password: tmppass Retype new password: tmppass passwd: password updated successfully pi@raspberrypi:~ $ exit
先ほど、作成した仮のユーザーでログインします。
ユーザー名 : tmpuser
パスワード : tmppass
Linux raspberrypi 5.4.51-v7l+ #1327 SMP Thu Jul 23 11:04:39 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Could not chdir to home directory /home/tmpuser: No such file or directory SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. tmpuser@raspberrypi:/$ sudo usermod -l orange pi ← 「pi」ユーザーを「orange」に変更 We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for tmpuser: tmppass tmpuser@raspberrypi:/$ sudo usermod -d /home/orange -m orange ← ホームディレクトリーの変更 tmpuser@raspberrypi:/$ sudo groupmod -n orange pi ← 「pi」グループを「orange」に変更 tmpuser@raspberrypi:/$ exit
「pi」ユーザーの変更が出来ましたので、仮のユーザーは削除して、変更したユーザー名のパスワードを変更します。
ユーザー名 : orange
パスワード : raspberry
Linux raspberrypi 5.4.51-v7l+ #1327 SMP Thu Jul 23 11:04:39 BST 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. orange@raspberrypi:~ $ sudo userdel tmpuser ← 仮のユーザーを削除 We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for orange: raspberry ← まだデフォルトのまま orange@raspberrypi:~ $ sudo passwd orange ← パスワードの変更 New password: orangepass Retype new password: orangepass passwd: password updated successful
IPアドレスの設定
デフォルトの状態では、DHCPにてIPアドレスが割り当てられるので、サーバー用途であれば、IPアドレスは固定化します。
$ sudo cp -p /etc/dhcpcd.conf /etc/dhcpcd.conf.original $ sudo vi dhcpcd.conf : (割愛) # Example static IP configuration: interface wlan0 ← インターフェース名「wlan0」を設定 static ip_address=198.51.100.11/24 ← IPアドレスを設定 #static ip6_address=fd51:42f8:caae:d92e::ff/64 ← コメントアウトのまま static routers=198.51.100.1 ← デフォルトゲートウェイを設定 static domain_name_servers=198.51.100.21 ← ネームサーバを設定 : (割愛) $ diff dhcpcd.conf dhcpcd.conf.original 44,45c44,45 < #interface eth0 < #static ip_address=192.168.0.10/24 interface wlan0 static ip_address=198.51.100.11/24 47,48c47,48 < #static routers=192.168.0.1 < #static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1 static routers=198.51.100.1 static domain_name_servers=198.51.100.21
ホスト名の変更
$ sudo cp -p /etc/hostname /etc/hostname.original $ sudo vi hostname raspi01 ← 新しいホスト名に変更 $ diff hostname hostname.original 1c1 < raspi01 --- > raspberrypi $ sudo cp -p hosts hosts.original $ sudo vi hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.1.1 raspi01 ← 新しいホスト名に変更 $ diff hosts hosts.original 6c6 < 127.0.1.1 raspi01 --- > 127.0.1.1 raspberrypi $ sudo systemctl reboot
タイムゾーンの変更と時刻同期の設定
タイムゾーンを日本時間に変更します。
時刻同期の設定も行います。
Raspberry Pi には、RTCがないので、timesyncdを使用して時刻同期を行います。
$ sudo raspi-config nonint do_change_timezone Asia/Tokyo ← タイムゾーン設定 Current default time zone: 'Asia/Tokyo' Local time is now: Wed Aug 12 00:38:18 JST 2020. Universal Time is now: Tue Aug 11 15:38:18 UTC 2020. $ timedatectl status Local time: Fri 2020-08-14 08:58:03 JST Universal time: Thu 2020-08-13 23:58:03 UTC RTC time: n/a Time zone: Asia/Tokyo (JST, +0900) System clock synchronized: yes NTP service: active ← 動作している RTC in local TZ: no $ sudo cp -p /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.original $ sudo vi /etc/systemd/timesyncd.conf : (割愛) [Time] NTP=time.google.com ← 正のタイムサーバーを設定 FallbackNTP=ntp.jst.mfeed.ad.jp ntp.nict.jp ← 副のタイムサーバーを設定 #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048 $ sudo systemctl daemon-reload $ sudo systemctl restart systemd-timesyncd.service $ systemctl status systemd-timesyncd.service ● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/systemd-timesyncd.service.d mqdisable-with-time-daemon.conf Active: active (running) since Mon 2020-11-23 22:18:31 JST; 13s ago Docs: man:systemd-timesyncd.service(8) Main PID: 29202 (systemd-timesyn) Status: "Synchronized to time server for the first time 216.239.35.12:123 (time.google.com)." Tasks: 2 (limit: 2182) CGroup: /system.slice/systemd-timesyncd.service └29202 /lib/systemd/systemd-timesyncd
各種ソフトウェアのインストール
必要な各種ソフトウェアをインストールします。
$ sudo apt install dnsutils vim nmap : (割愛) Do you want to continue? [Y/n] y : (割愛)