1
1

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 3 years have passed since last update.

未設定のラズパイにsshログインを行いコマンドを流し込む

Last updated at Posted at 2021-02-08

同じネットワークにいる未設定のラズパイに ssh ログインします。

ssh の有効化

ラズパイOSが書き込こまれている SDカードを PC(ubuntu) に差し、ssh という空のファイルを作成します。

touch /media/$USERNAME/boot/ssh ;

ラズパイを起動してIPアドレスを調べます。

※ラズパイ側で ifconfig で DHCP な IPアドレスを取得できますが、キーボード等なるべく触りたくないので、ubuntu 側でIPアドレスを調べます。

IPアドレスの調査

sudo apt install -y arp-scan ;
ifconfig ; #インターフェイス情報の取得
sudo arp-scan --interface wlp5s0 -l ;

得られる情報

192.168.0.111	xx:xx:xx:xx:xx:xx	Raspberry Pi Foundation

ubuntuからラズパイにsshログイン

ssh pi@192.168.0.111 ;

ログイン情報

項目
ユーザー名 pi
パスワード raspberry

ラズパイをまとめてインストールしたい場合に便利そうです。

wifiでの接続を行う場合は

HOGE=$(cat<<TEXT
country=JP
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="ssidname"
    psk="password"
}
TEXT
)
echo "$HOGE" > /media/USERNAME/xxxxsd_card_idxxxx/boot/wpa_supplicant.conf ;

これでwpa_supplicant.conf ファイルに下記情報が書き込まれます

country=JP
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="ssid_name"
    psk="password"
}

あとはsshでログインを行って好きなコマンドを流し込みます。

1つの端末向け

# !/bin/bash

ssh pi@192.168.0.111 <<EOC
hostname ;
wget http://hgoehoge.com/install.sh ;
bash install.sh;
EOC

複数の端末向け

# !/bin/bash

HOSTS="192.168.0.111 192.168.0.112 192.168.0.113"

for i in ${HOSTS}; do

ssh pi@$i <<EOC
hostname ;
wget http://hgoehoge.com/install.sh ;
bash install.sh;
EOC

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?