Top/Security/ssh

目次

sshキー

sshキーの生成

$ ssh-keygen -t ed25519 -C account@hostname
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/account/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/account/.ssh/id_ed25519
Your public key has been saved in /home/account/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:6rp4b8YlVK5k8auztiFK5QuZsjQIRCf5yFBrkUS50Xg account@hostname
The key's randomart image is:
+--[ED25519 256]--+
| ***             |
|o.BoE . .        |
|o.=+   =         |
|.+..  + o        |
|.   .+ .S.       |
|o  =  o.o        |
|oo= o.o+         |
|.+.+.+B.         |
|. o.+B=+         |
+----[SHA256]-----+
$

公開鍵認証の設定

  1. ローカルにて
    • ssh キーを ~/.ssh/authorized_keys に登録する
      [user@exaple.com:0 .ssh]$ ssh-copy-id user@exaple.com
      /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
      user@exaple.com's password: 
      Permission denied, please try again.
      user@exaple.com's password: 
      
      Number of key(s) added: 1
      
      Now try logging into the machine, with:   "ssh 'user@exaple.com'"
      and check to make sure that only the key(s) you wanted were added.
      

ssh-agent / ssh-add

ssh で接続できないとき

  1. デバッグモードで接続してみる
    $ ssh -vvv ${REMOTE_HOST}
  2. ログを見てみる(要管理者権限)
    $ less /var/log/auth.log

ssh による無認証ログイン

環境設定

  1. sshキーの生成 で生成したキーのうち、公開鍵(${HOME}/.ssh/<public-key-file>.pub)を、scp や sftp 等を使って接続先サーバの ${HOME}/.ssh 下に配置する。
  2. 接続先サーバにログインし、配置した公開鍵を登録する。
    $ ssh-copy-id -i ~/.ssh/<public-key-file>.pub <user@host>
  3. (上記が終わったら、サーバからはログアウトする。)

接続

  1. 接続先サーバに ssh 接続する。初回はパスワードを訊かれるので入力する必要があるが、その後は無認証ログインとなる。
    $ ssh <user@host>

明示的にパスワード認証ログインする

Links


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-03-31 (日) 19:39:53