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?

More than 1 year has passed since last update.

ssh接続を簡単にする

Posted at

ssh鍵認証

準備

まだmacに.ssh/id_rsa.pubの鍵がない場合はmacで下記のコマンドを実行し生成します

mac:~ $ ssh-keygen -t rsa -b 4096

鍵認証で入れるようにmac側の公開鍵をラズパイに設定します。

mac:~ $ ssh-copy-id -i .ssh/id_rsa.pub pi@raspberrypi.local
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
pi@raspberrypi.local's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'pi@raspberrypi.local'"
and check to make sure that only the key(s) you wanted were added.

確認

mac:~ $ ssh pi@raspberrypi.local
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 17 16:02:31 2023 from 240b:11:bc00:7d00:3c19:1e17:4098:36d5
pi@raspberrypi:~ $ 

パスワードを入力することなく、入れるようになった。

ニックネームでログインできるようにする

設定ファイルの作成

macの~/.ssh/configに下記の内容で設定する。追記またはファイルを新規作成する。

Host raspi 
HostName raspberrypi.local 
port 22
User pi 
IdentityFile ~/.ssh/id_rsa

ニックネームでログイン

mac:~ $ ssh raspi
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 17 16:09:13 2023 from 240b:11:bc00:7d00:3c19:1e17:4098:36d5
pi@raspberrypi:~ $ 
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?