0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspberry Piをいじっているときによく使うコマンド等

Last updated at Posted at 2018-05-29

この記事について…

普段はRaspberry Piとは無縁なプログラマだったんですが、斯く斯く然々で色々やってみることになりました。普段はWindowsしかいじらないのでLinuxは超初心者ですが、備忘録を兼ねてよく使うコマンド等を纏めておきます。
尚、2018/05/17現在 Raspbian Stretch Lite 2018-04-18リリースを使用しています。

コマンド

# Raspbian固有の設定ツール SSHやSPIの有効化、ホスト名の変更等だいたいできます
$ sudo raspi-condig

# パッケージ操作
# 更新
$ sudo apt update && sudo apt -y upgrade && sudo apt -y autoremove && sudo apt -y autoclean
$ sudo apt -y dist-upgrade
# インストール、削除
$ sudo apt install package_name
$ sudo apt remove package_name
# インストール済み一覧
$ apt list --installed

# SSH鍵の作成
$ ssh-keygen -t rsa -b 4096 -f id_rsa_file_name -C "abc@sample.com"

# アクセス権限の変更
$ chmod 666 file_path

# プロセス管理
# 表示(auxはオプション)
$ ps aux
# 強制終了
$ kill process_id

# パフォーマンスモニタリング
$ top
  # topコマンド実行中、下記のショートカットで表示状態変更可能
  # Shift+P : CPU使用率順
  # Shift+M : メモリ使用率順
  # Shift+T : 実行時間順

# 外部ストレージマウント
$ sudo fdisk -l # パーティションの状況を調べる、/dev/sda*を探す
$ sudo mkdir /mnt/usb1 # 任意のディレクトリ作成
$ sudo chmod 777 /mnt/usb1 # 本来は適切なアクセス権限を与える
$ sudo blkid /dev/sda1 # UUID確認
  # ...UUID="xxxxxxxx-xxxx-...xxxx"...
$ sudo vi /etc/fstab # fstab追記
  # ext4の場合
  # UUID=xxxxxxxx-xxxx-...xxxx /mnt/usb1 ext4 defaults,noatime,nofail 0 0
  # FAT32の場合
  # UUID=xxxxxxxx-xxxx-...xxxx /mnt/usb1 vfat user,rw,noatime,nofail,umask=111,dmask=000 0 0
$ sudo reboot # 再起動すると自動マウント
$ df # マウントされたことを確認
$ vi /mnt/usb1/a.txt # rootでなくても読み書き可能

$ sudo mount /dev/sda1 /mnt/usb1 # 手動マウント
$ sudo umount /dev/sda1 # 手動アンマウント

# Gitインストール
$ sudo apt install git
$ git config --global user.name "abc defg"
$ git config --global user.email "abc@sample.com"

# シャットダウン・再起動
$ sudo shutdown now
$ sudo reboot

設定

  • 固定IPアドレスの設定
/etc/dhcpcd.conf
  .
  .
# ファイル末尾に以下を追記
interface eth0
static ip_address=xxx.xxx.xxx.xxx/xx
static routers=xxx.xxx.xxx.xxx
static domain_name_servers=xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx
  • Wi-Fi設定
$ cd /etc/wpa_supplicant
# wpa_supplicant.confのアクセス権限を一時的に変更
$ sudo chmod 666 ./wpa_supplicant.conf
$ sudo wpa_passphrase SSID password >> wpa_supplicant.conf
$ vi wpa_supplicant.conf # 後述のように内容を変更
$ sudo chmod 600 ./wpa_supplicant.conf
./wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="SSID"
        #psk="password" # この行は平文パスワードなので削除
        psk=xxxxxxxxxx
        scan_ssid=1 # ステルスSSIDを使用している場合はこの行を追加
}

お役立ち情報

  • Raspberry Pi初回起動時からSSH接続したい場合は、/boot/sshというファイル(拡張子なし)をWindows Explorer等からSDカードのbootフォルダに直接作成するとSSHが有効になる

参考

USBメモリのマウント
https://mmbrothers.exblog.jp/16948851/
Linuxパフォーマンス調査などで使うコマンドメモ
https://qiita.com/toshihirock/items/0e0b20064730469e93e6
topコマンドで覚えておきたい使い方14個
https://orebibou.com/2015/07/top%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%A7%E8%A6%9A%E3%81%88%E3%81%A6%E3%81%8A%E3%81%8D%E3%81%9F%E3%81%84%E4%BD%BF%E3%81%84%E6%96%B914%E5%80%8B/

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?