His Masters' Voices Wiki

よろずのことの書き残し

ユーザ用ツール

サイト用ツール


nas:readynas_duo_v2_openwrt_useradd

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
nas:readynas_duo_v2_openwrt_useradd [2022/05/28 19:05] – 作成 nipa28nas:readynas_duo_v2_openwrt_useradd [2022/05/28 21:46] (現在) – [一般ユーザーでSSHアクセスする] nipa28
行 20: 行 20:
 手順 手順
 ---- ----
 +
 +ユーザー管理に役立ちそうなパッケージを追加する。
  
 ``` ```
行 30: 行 32:
  
 ``` ```
 +
 +### /homeを作成
 +
 +ユーザーのホームディレクトリを置くため、データ領域の/dev/md3(/mnt/md3にマウントされている)に homeディレクトリを作成した。
 +ルート`/`に `/mnt/md3/home` へのシンボリックリンクを作成した。
 +
 +```
 +root@OpenWrt:~# mkdir /mnt/md3/home
 +root@OpenWrt:~# ln -s /mnt/md3/home /
 +root@OpenWrt:~# ll /home
 +lrwxrwxrwx    1 root     root            13 May 28 20:35 /home -> /mnt/md3/home/
 +root@OpenWrt:~# 
 +
 +```
 +
 +### 一般ユーザーを追加
 +
 +```
 +root@OpenWrt:~# useradd -m -d /home/hiroshi -s /bin/ash -U hiroshi
 +root@OpenWrt:~# passwd hiroshi
 +Changing password for hiroshi
 +New password: 
 +Retype password: 
 +passwd: password for hiroshi changed by root
 +root@OpenWrt:~# ls /home/
 +hiroshi
 +root@OpenWrt:~# 
 +
 +```
 +
 +### 一般ユーザーにsudo権限付与
 +
 +/etc/sudoersを編集
 +
 +```
 +root@OpenWrt:~# visudo
 +```
 +
 +この部分のコメントを外す。
 +```
 +## Uncomment to allow members of group sudo to execute any command
 +%sudo   ALL=(ALL:ALL) ALL
 +
 +```
 +
 +sudoグループを作成し、一般ユーザーをsudoグループに追加
 +
 +```
 +root@OpenWrt:~# groupadd --system sudo
 +root@OpenWrt:~# usermod -aG sudo hiroshi
 +root@OpenWrt:~# id hiroshi
 +uid=1000(hiroshi) gid=1000(hiroshi) groups=1000(hiroshi),999(sudo)
 +root@OpenWrt:~# 
 +
 +```
 +
 +### 一般ユーザーでSSHアクセスする
 +
 +
 +一般ユーザーにsuして、 ~/.ssh/ディレクトリ、 ~/.ssh/authorized_keysファイルを作成する。
 +
 +~/.ssh/authorized_keysファイルには、公開鍵の内容を貼り付ける
 +
 +```
 +root@OpenWrt:~# su - hiroshi
 +
 +
 +BusyBox v1.35.0 (2022-05-20 19:00:24 UTC) built-in shell (ash)
 +
 +  _______                     ________        __
 +       |.-----.-----.-----.|  |  |  |.----.|  |_
 +     ||  _  |  -__|     ||  |  |  ||   _||   _|
 + |_______||   __|_____|__|__||________||__|  |____|
 +          |__| W I R E L E S S   F R E E D O M
 + -----------------------------------------------------
 + OpenWrt SNAPSHOT, r19689-19ef3b54f4
 + -----------------------------------------------------
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ mkdir ~/.ssh
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ chmod 700 ~/.ssh
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ vi ~/.ssh/authorized_keys
 +<公開鍵の内容を貼り付ける>
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ chmod 600 ~/.ssh/authorized_keys
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$
 +```
 +
 +公開鍵は次のようにして作ることができる。(*.pubの方)
 +
 +```
 +hiroshi@VPCF24AJ-ubuntu:~$ ssh-keygen -t rsa -b 4096 -C "ReadyNAS" -f ~/.ssh/rndv2
 +                                  :
 +hiroshi@VPCF24AJ-ubuntu:~$ cat ~/.ssh/rndv2.pub 
 +<公開鍵ファイルの内容>
 +hiroshi@VPCF24AJ-ubuntu:~$ 
 +```
 +
 +このように、一般ユーザーで OpenWrt へログインできるようになった。
 +
 +```
 +hiroshi@VPCF24AJ-ubuntu:~$ ssh hiroshi@192.168.10.2
 +
 +
 +BusyBox v1.35.0 (2022-05-20 19:00:24 UTC) built-in shell (ash)
 +
 +  _______                     ________        __
 +       |.-----.-----.-----.|  |  |  |.----.|  |_
 +     ||  _  |  -__|     ||  |  |  ||   _||   _|
 + |_______||   __|_____|__|__||________||__|  |____|
 +          |__| W I R E L E S S   F R E E D O M
 + -----------------------------------------------------
 + OpenWrt SNAPSHOT, r19689-19ef3b54f4
 + -----------------------------------------------------
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ 
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ df ~
 +Filesystem           1K-blocks      Used Available Use% Mounted on
 +/dev/md3             2878354352        48 2732067232   0% /mnt/md3
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ 
 +
 +```
 +
 +ホームディレクトリは、RAID1を組んだReadyNASのHDD上にあるので、ディスク容量もたっぷりありますね。
 +
 +
 +### ホスト名でSSHアクセス
 +
 +なんと、 openwrt.local でもアクセスできますね8-O
 +
 +```
 +hiroshi@VPCF24AJ-ubuntu:~$ ssh hiroshi@openwrt.local
 +The authenticity of host 'openwrt.local (192.168.10.2)' can't be established.
 +ED25519 key fingerprint is SHA256:+PRsgEp2u4uYinKRrsU4fVU9a9oHTceK8Gp/nDtXaCw.
 +This host key is known by the following other names/addresses:
 +    ~/.ssh/known_hosts:1: [hashed name]
 +Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 +Warning: Permanently added 'openwrt.local' (ED25519) to the list of known hosts.
 +
 +
 +BusyBox v1.35.0 (2022-05-20 19:00:24 UTC) built-in shell (ash)
 +
 +  _______                     ________        __
 +       |.-----.-----.-----.|  |  |  |.----.|  |_
 +     ||  _  |  -__|     ||  |  |  ||   _||   _|
 + |_______||   __|_____|__|__||________||__|  |____|
 +          |__| W I R E L E S S   F R E E D O M
 + -----------------------------------------------------
 + OpenWrt SNAPSHOT, r19689-19ef3b54f4
 + -----------------------------------------------------
 +hiroshi@OpenWrt:/mnt/md3/home/hiroshi$ 
 +
 +```
 +
 +
 +
 +---
 +
 +### 参考
 +
 +下記サイトを参考にさせていただきました。
 +
 +https://www.hogepiyo.com/wp/?p=1213
 +
  
nas/readynas_duo_v2_openwrt_useradd.1653732356.txt.gz · 最終更新: 2022/05/28 19:05 by nipa28