パスフレーズを要求されずに NAS に ssh ログイン

(2025-10-05)

これも何度もやったことがあるのですが記憶に残っておらず、NAS のユーザー名を「taro」から「moheno」に変えたので ssh に関しても変更する必要があります。

クライアント(ローカルの linux mint)でキー作成

例によって chatGPT に訊きました。この辺に関しては chatGPT は完璧です。

最近は Ed25519 の方が推奨されることも多いようです。

ssh-keygen -t ed25519 -C "your_email@example.com"

your_email@example.com は大した意味はないようで、何のキーかわからなくなるのでコメントのような役割ということらしいです。

公開鍵をNASに登録

以下のようなコマンドを実行します。

Terminal window
cat ~/.ssh/id_ed25519.pub | ssh -p 12345 moheno@192.168.0.20 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

たったこれだけで以下のようなことが実行されます。

  1. 自分の公開鍵の内容を出力
  2. NAS にSSH接続(パスワードで1回だけログイン)
  3. NAS側で .ssh ディレクトリを作成(存在しない場合のみ)
  4. 公開鍵を追記
  5. ディレクトリの権限を適切に設定
  6. ファイルの権限を適切に設定

実際にログインする

以下のようにしてログインを確認します。

Terminal window
moheno@moheno-Vostro-3681:~$ ssh -p 12345 moheno@192.168.0.20
Using terminal commands to modify system configs, execute external binary
files, add files, or install unauthorized third-party apps may lead to system
damages or unexpected behavior, or cause data loss. Make sure you are aware of
the consequences of each command and proceed at your own risk.
Warning: Data should only be stored in shared folders. Data stored elsewhere
may be deleted when the system is updated/restarted.
moheno@NAS720:~$

chatGPT ってすごいですね。