LoginSignup
5
3

More than 5 years have passed since last update.

Raspberry Piまとめ

Last updated at Posted at 2017-05-17

RasPiコマンドまとめ

  • Shutdown $ sudo shutdown -h now
  • Reboot $ sudo shutdown -r now, $ sudo reboot
  • ssh config (.ssh/config) Host Sample HostName xxx.xxx.xxx.xxx User sampleUser ServerAliveInterval xx

RasPi設定まとめ

Raspiのupdate

$ sudo rpi-updateで実行

その後$ sudo rebootで再起動

rootのパスワード設定

pi@raspberrypi:~ $ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

root userでログインできるか確認

pi@raspberrypi:~ $ su
Password:
root@raspberrypi:/home/pi# exit

pi userのパスワード設定

pi@raspberrypi:~ $ sudo passwd pi
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

user (sampleUser)加える

pi@raspberrypi:~ $ sudo adduser sampleUser
Adding user `sampleUser' ...
Adding new group `sampleUser' (1001) ...
Adding new user `sampleUser' (1001) with group `sampleUser' ...
Creating home directory `/home/sampleUser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for sampleUser
Enter the new value, or press ENTER for the default
    Full Name []: < 空白でOK
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:

piと同様の権限をsampleUserに渡す

まずpiがどの権限を持ってるのか確認

pi@raspberrypi:~ $ groups pi
pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio

この権限をsampleUserに渡し、最後に$ groups sampleUserで権限確認

pi@raspberrypi:~ $ sudo usermod -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input,spi,gpio sampleUser

SSH KeyをRasPiに渡す

Terminal 2つ [Local]と[Raspi]開きましょう (keygenミスったりすると入れなくなります)

1. Keyを作成

[local]$ ssh-keygen -t rsaにより~/.ssh/id_rsaにpublic keyとprivate key作成される

2. KeyをRaspi側に移す

[local]$ scp id_rsa.pub yourRasPiAddr:~/.sshpublic Keyを移動

3. public Keyをauthorized_keysに書き出す

[Raspi]@raspberrypi:~/.ssh $ cat id_rsa.pub >> authorized_keys
[Raspi]@raspberrypi:~/.ssh $ ls -a
.  ..  authorized_key  id_rsa.pub

4. 権限設定

[Raspi]@raspberrypi:~/.ssh $ chmod 600 authorized_key
[Raspi]@raspberrypi:~ $ chmod 700 .ssh
[Raspi]@raspberrypi:~/.ssh $ su
Password:
root@raspberrypi:/home/[Raspi]/.ssh# cd /etc/ssh

5. デーモン書き換え

root@raspberrypi:/etc/ssh# vim sshd_config

以下のファイル書き換え

AuthorizedKeysFile      %h/.ssh/authorized_keys
PasswordAuthentication no
PermitRootLogin no

6. デーモン再起動

[Raspi]@raspberrypi:~/.ssh $ sudo /etc/init.d/ssh restart
[ ok ] Restarting ssh (via systemctl): ssh.service.

7. RasPiに[local]から接続

5
3
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
5
3