LoginSignup
4
1

More than 3 years have passed since last update.

Raspberry Pi ssh設定方法(Mac編)

Posted at

Raspberry Pi ssh設定方法(Mac編)

sshの有効化

RaspberryPiのGUIからターミナルを起動して、bootディレクトリ配下にsshファイルを作成

cd /boot

sudo touch ssh

再起動

sudo reboot

再起動後、下記のメッセージが表示される

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and run Raspberry Pi Configuration to set a new password.

ssh接続

デフォルト設定

ユーザー名: pi
パスワード: raspberry

IPアドレスを確認

ifconfig

wlan0のinetに記載されているIPアドレスを確認

ssh接続

ホストPCで入力

ssh pi@IPアドレス

接続できるのを確認後、raspberrypiからログアウト

exit

鍵ファイルの設定

鍵ファイルを作成

mkdir ~/.ssh

cd ~/.ssh

ssh-keygen

鍵ファイルのファイル名を聞かれるのでid_rsa_raspberrypiを設定

※ ファイル名は好きに設定してください。

ホストPCのパーミッションを設定

chmod 700 .ssh
chmod 600 id_rsa_raspberrypi

公開鍵をRasberryPiへ送信

scpでホストPCから、RaspberryPiへ送信

scp -p 22 id_rsa_raspberrypi.pub pi@192.168.1.196:~/

RaspberryPiに.sshフォルダを作成

ssh pi@IPアドレス

mkdir ~/.ssh

authorized_keysに公開鍵を設定

cat ~/id_rsa_raspberrypi.pub >> .ssh/authorized_keys

フォルダとファイルにパーミッションを設定

chmod 700 .ssh
chmod 600 .ssh/authorized_keys

RaspberryPiからログアウト

exit

鍵ファイルを使用してログイン

鍵ファイルでログインできるのを確認

ssh -i ~/.ssh/id_rsa_raspberrypi pi@192.168.1.196

vi設定

sudo apt-get -y --purge remove vim-common vim-tiny
sudo apt-get -y install vim

cat <<EOS > ~/.vimrc
set nocompatible
set backspace=indent,eol,start
set autoindent
set nowrap
set ruler
syntax on
EOS

sshの設定ファイルを修正

sudo chmod 777 /etc/ssh/sshd_config

vi /etc/ssh/sshd_config

sshd_config 設定「PubkeyAuthentication」コメントを外す

#PubkeyAuthentication yes

PubkeyAuthentication yes

sshd_config 設定「AuthorizedKeysFile」コメントを外す

#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

sshd_config 設定「PasswordAuthentication」コメントを外すしてNoにする

#PasswordAuthentication yes

PasswordAuthentication no

パーミッションを戻す

sudo chmod 644 /etc/ssh/sshd_config

再起動して完了

sudo reboot

接続確認

下記で接続できないことを確認

ssh pi@ipアドレス

下記で接続できることを確認

ssh -i ~/.ssh/id_rsa_raspberrypi pi@192.168.1.196
4
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
4
1