0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi 4 Model BのSSH設定

Posted at

Raspberyy Pi 4 Model B SSH 鍵認証 メモ

用意したもの
・Windows PC
・Raspberry Pi 4 Model B
・Tera Term

クライアント側の操作

# 秘密鍵 公開鍵の作成
$> ssh-keygen -t rsa

# その後入力を促す文字が表示されるが入力せずにEnter

鍵が生成されたか確認

$> ls ~/.ssh/

    # id_rsa.pubが公開鍵
    ディレクトリ: C:\Users\users\.ssh


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2024/01/01     00:00           xxxx id_rsa
-a----        2024/01/01     00:00           xxxx id_rsa.pub

生成した公開鍵をラズパイにSCPで送信

$> scp ~/.ssh/id_rsa.pub [user]@192.168.x.x:~

Raspberry Pi側の操作

# .sshフォルダが存在するか確認
$> cd ~
$> ls -a

# 存在しない場合は作成
$> mkdir .ssh

鍵を.ssh配下に追加

$> cat id_rsa.pub >> .ssh/authorized_keys

# 権限の変更
$> chmod 600 .ssh/authorized_keys

# 元のファイルを削除
$> rm id_rsa.pub

/etc/ssh/sshd_config の編集

$> sudo vi /etc/ssh/sshd_config
~~~ ファイルの末尾に追加 ~~~
# ポートの設定
Port 22 

# rootログインの禁止
PermitRootLogin no

# 鍵認証を有効化
PubkeyAuthentication yes

# パスワード認証を無効化
PasswordAuthentication no

sshサーバーの再起動

$ sudo /etc/init.d/ssh restart

上記対応で公開鍵を用いたSSH接続が可能

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?