LoginSignup
1
0

More than 3 years have passed since last update.

ラズパイでCentOS7を起動した後に設定したこと

Posted at

はじめに

今回は、前回の記事の続きでRaspberry Pi 3b+にCentOS7をインストールした後に行った設定についてまとめます。

タイムゾーンの設定

上書きしますかと聞かれるのでOKしてください。

cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

selinuxの無効化

まずは、selinuxが有効になっているかどうかを調べます。 getenforce コマンドで Enforcing が出たら有効化されています。 Disabled だった場合はすでに無効化されているので次のステップに移りましょう。

# getenforce
Enforcing

有効化されていますね。 /etc/selinux/config を修正しましょう。

# vi /etc/selinux/config
/etc/selinux/config
SELINUX=enforcing

ここの設定を

/etc/selinux/config
SELINUX=disabled

こう修正します。

設定出来たらサーバを再起動してもう一度 getenforce コマンドを実行してみましょう。

# getenforce
Disabled

無効化されましたね。これでOKです。

chronyの設定(時刻同期)

こちらは

の記事を参考にさせていただきました。
とはいいつつ、設定はほとんど変更していません。
以下、私の設定

/etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.nict.jp iburst
server 0.jp.pool.ntp.org iburst 
server 1.jp.pool.ntp.org iburst

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

SDカードのパーティションを拡張

今回、32GBのSDカードを使用しているのですが、1.4GBしか認識されていません。

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.4G  994M  352M  74% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1  667M   43M  625M   7% /boot
tmpfs            93M     0   93M   0% /run/user/0

以下のサイトを参考にさせていただきながらパーティションの拡張を行いました。

# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/mmcblk0: 32.0 GB, 32010928128 bytes, 62521344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cc7a5

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048     1370111      684032    c  W95 FAT32 (LBA)
/dev/mmcblk0p2         1370112     2369535      499712   82  Linux swap / Solaris
/dev/mmcblk0p3         2369536     5298175     1464320   83  Linux

Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted

Command (m for help): p

Disk /dev/mmcblk0: 32.0 GB, 32010928128 bytes, 62521344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cc7a5

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048     1370111      684032    c  W95 FAT32 (LBA)
/dev/mmcblk0p2         1370112     2369535      499712   82  Linux swap / Solaris

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (2369536-62521343, default 2369536):
Using default value 2369536
Last sector, +sectors or +size{K,M,G} (2369536-62521343, default 62521343):
Using default value 62521343
Partition 3 of type Linux and of size 28.7 GiB is set

Command (m for help): p

Disk /dev/mmcblk0: 32.0 GB, 32010928128 bytes, 62521344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cc7a5

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048     1370111      684032    c  W95 FAT32 (LBA)
/dev/mmcblk0p2         1370112     2369535      499712   82  Linux swap / Solaris
/dev/mmcblk0p3         2369536    62521343    30075904   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

/dev/mmcblk0p3 に割り当てられていたものを一度削除してから、SDカードの残りの領域を指定し再作成した形になります。

ワーニングが出たのでそれに従いラズパイを再起動。

# reboot

改めてログインしましたが、まだこの時点では拡張されていません。

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.4G  994M  352M  74% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1  667M   43M  625M   7% /boot
tmpfs            93M     0   93M   0% /run/user/0

resize2fs コマンドにてファイルシステムの拡張をします。

# resize2fs /dev/mmcblk0p3
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mmcblk0p3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/mmcblk0p3 is now 7518976 blocks long.

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  996M   28G   4% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1  667M   43M  625M   7% /boot
tmpfs            93M     0   93M   0% /run/user/0

これでOK。

yum update

yum update します。

# yum update

<省略>

Complete!

Wifiの設定

nmcli コマンドを使います。
まずは近場にあるWifiスポット検索。

# nmcli d wifi list
IN-USE  SSID                MODE   CHAN  RATE        SIGNAL  BARS  SECURITY
        aaaaa      Infra  6     195 Mbit/s  75      ???_  WPA1 WPA2
        bbbbb      Infra  36    540 Mbit/s  64      ???_  WPA1 WPA2
        ccccc      Infra  2     260 Mbit/s  44      ??__  WPA2
        ddddd      Infra  4     540 Mbit/s  32      ??__  WPA1 WPA2
        eeeee      Infra  11    130 Mbit/s  32      ??__  WPA1 WPA2
        fffff      Infra  1     130 Mbit/s  30      ?___  WPA1 WPA2
                        ・
                        ・
                        ・

任意のスポットに接続。

# nmcli d wifi connect [SSID] password [password]

作業ユーザの作成&設定

常にrootで作業するのは良くないので、作業用のユーザを作成します。

# useradd -G wheel hogehoge
# passwd hogehoge

したら試しにログインして、sudoも使えるか確認しましょう。

Last login: Wed Apr 29 12:10:04 2020
[hogehoge@localhost ~]$
[hogehoge@localhost ~]$ sudo ls -la

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 hogehoge:
total 24
drwx------  2 hogehoge hogehoge 4096 Apr 29 12:10 .
drwxr-xr-x. 3 root  root  4096 Apr 29 12:09 ..
-rw-------  1 hogehoge hogehoge    8 Apr 29 12:10 .bash_history
-rw-r--r--  1 hogehoge hogehoge   18 Apr  1 02:28 .bash_logout
-rw-r--r--  1 hogehoge hogehoge  193 Apr  1 02:28 .bash_profile
-rw-r--r--  1 hogehoge hogehoge  231 Apr  1 02:28 .bashrc

次は、公開鍵情報の追加です。僕のPCのOSはWindows10で、TeraTerm + Pagentを利用して鍵の管理をしているのでそちらで作成した鍵を使用します。

まずはホームディレクトリ下に .ssh ディレクトリを作成します。

$ mkdir .ssh
$ chmod 700 .ssh

そこに authorized_keys というファイルを作成し、ローカルPC側で作成した鍵の公開鍵をコピペします。

$ cd .ssh
$ sudo vi authorized_keys

鍵の登録が終わったら設定ファイルの編集です。 /etc/ssh/sshd_config を編集します。

sshd_config
PermitRootLogin no   <- "yes"となっていた場合は"no"に変更。rootでのログインを禁止します。

PasswordAuthentication no  <- "yes"となっていた場合は"no"に変更。パスワード入力によるログインを禁止します。

設定が終わったらリロード。

$ sudo systemctl reload sshd

まとめ

今回は、前回の記事の続きでRaspberry Pi 3b+にCentOS7をインストールした後に行った設定についてまとめてみました。これ自体は本当に最低限のもので、抜けている部分もあるかもしれませんので何かセキュリティ的な問題がある場合はご教授いただけると幸いです。

1
0
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
0