1
1

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 5 years have passed since last update.

クライアント側におけるSSHのパスワード認証と公開鍵認証の設定

Posted at

サーバー側で有効になっている認証方法を確認する方法

下記の例だと、publickey認証とpassword認証が有効になっている事がわかる。

$ ssh -v IPADDR
    ~省略~
debug1: Authentications that can continue: publickey,password
    ~省略~

password認証

有効なユーザー、パスワードを指定して認証を行う方法

$ ssh USER@IPADDR
USER@IPADDR's password:         <---パスワードを入力する

password認証を無効にする方法
password認証はサーバー、クライアント共にデフォルトで有効になっている。
password認証を無効にするにはコンフィグファイルに、次の行を追加すれば良い。

PasswordAuthentication no

publickey認証

  1. 公開鍵と秘密鍵のペアを作成する
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX user@user
The key's randomart image is:

tオプションで暗号の種類を選択できる。
特に指定しない場合はRSAが選択される。

※OpenSSH7.0よりdsaの使用はデフォルトで無効になっている。http://www.openssh.com/txt/release-7.0

  1. 公開鍵をリモートホストへデプロイする。
$ ssh-copy-id -i ~/.ssh/id_rsa.pub USER@IPADDR

iオプションで1の手順で作成した公開鍵を指定する。

sshクライアントの挙動をデフォルトから変更する

sshクライアントの挙動をデフォルトから変更するには「コマンドオプションを指定する」あるいは「コンフィグファイルをカスタマイズ」します。

sshクライアントにおける設定の読み込み順序

  1. コマンドラインで指定した設定
  2. ~/.ssh/config
  3. /etc/ssh/ssh_config

設定項目毎に最初に読み込まれた設定が反映されるという事になっているため、
"1. コマンドラインで指定した設定"が最も優先され、"3. /etc/ssh/ssh_config"が最も優先度が低い。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?