とらりもんHOME  Index  Search  Changes  Login

sshのセキュリティ

サーバと鍵交換

サーバにパスワード認証なしでssh接続できるようにするにはサーバと鍵交換を行う。

端末で鍵を作成する。

$ cd ~/.ssh
$ ssh-keygen -t rsa
Enter file in which to save the key (/home/???/.ssh/id_rsa):(何も入力せずにエンターキーを押す) 
Enter passphrase (empty for no passphrase): (何も入力せずにエンターキーを押す)
Enter same passphrase again: (何も入力せずにエンターキーを押す)

公開鍵 (id_rsa.pub) と秘密鍵 (id_rsa) が作成される。 サーバにsshアクセス、ログインし、

$ vi ~/.ssh/authorized_keys

端末で,

$ cat ~/.ssh/id_rsa.pub

ここで出てきた内容を, サーバーのvi画面にコピペ。

これで, 端末からサーバーにsshしてみる。パスワードを聞かれずにログインできたら成功。パスワードを聞かれてしまったら、ファイルやディレクトリのアクセス権の設定をいじれば直ることが多い。

サーバーで:

$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*
$ chmod 755 ~/

端末で

$ chmod 755 ~/
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/id_rsa
それでも直らない時は, サーバーのログを見るとヒントがある:
$ sudo cat /var/log/auth.log

クライアントで,

$ ssh-agent
$ ssh-add

するとうまくいくこともある。

ユーザー単位でのアクセス制限(サーバー側)

http://www.server-memo.net/server-setting/ssh/allow-users.html

接続がtimeoutしないようにするには

(クライアント側の設定)

$ vi .ssh/config 
ServerAliveInterval 60
ServerAliveCountMax 3

https://rcmdnk.com/blog/2014/08/23/computer-linux-putty/

Last modified:2020/02/27 20:29:04
Keyword(s):
References:[とらりもんHOME]