MENU

溶けかけてるうさぎ HP GALLERY BLOG TOP RECENT ARTICLES POPULAR ARTICLES ABOUT THIS BLOG

CATEGORY

大学 (140) 仕事 (17) 航空宇宙 (104) 写真 (77) 旅行 (32) 飯・酒 (17) コンピュータ (118) その他 (44)

TAG

ARCHIVE

RECENT

【カメラ】X100 シリーズが好きすぎる(主にリーフシャッタ) 【カメラ】X100V から X100VI に買い替えました 【自宅サーバー】Google Domains から Cloudflare にドメインを移管 【カメラ】FUJIFILM XF レンズのサイズ比較ができるようにしてみた 【写真】自作写真閲覧ページにてフィルムシミュレーションで写真をフィルタできるようにした

【Ubuntu】Ubuntu ServerでのSSHで認証に使った公開鍵を記録する

事象発生日:2018-05-15

記事公開日:2018-05-15

アクセス数:2217

SSHポートフォワーディング用のサーバーを構築中である.

OpenSSHでログインに使用した公開鍵を記録する.

1.環境

Ubuntu Server 18.04 LTS

FUJITSU Server PRIMERGY TX1310 M3

4GB DDR4 x 1

2TB HDD x 1

 

Ubuntu Serverは「」で構築したものである.

さらに「」で基本的なSSH設定を終えている.

2.sshdのログレベルを変更

/etc/ssh/sshd_configを編集し,ログレベルを変更する.

$ diff sshd_config sshd_config.backup.20180515
27c27
< LogLevel VERBOSE
---
> #LogLevel INFO

構文チェックとサービス再起動.

$ sudo sshd -t
$ sudo /etc/init.d/ssh restart

3.公開鍵のハッシュがログに残っていることを確認

$ grep sshd /var/log/auth.log
...
May 15 07:29:59 ${host} sshd[1425]: Accepted publickey for ${user} from ${ip} port ${port} ssh2: RSA SHA256:${hash}
...

4.公開鍵のハッシュを確認

$ ssh-keygen -l -f ./.ssh/hoge.pub
2048 SHA256:${hash} ${clientUser}@${clientHost} (RSA)

これをログと突き合わせれば,SSHログインに使用された公開鍵がわかる.

5.sshdログを毎日保存

以下のようにcronを登録.

 

なお,にあるように,cronでは%をエスケープしないといけないことに注意.

$ crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
#
0 0 * * * grep sshd /var/log/auth.log > /home/${user}/log/sshd/$(date +\%Y\%m\%d_\%H\%M\%S).log
# */1 * * * * grep sshd /var/log/auth.log > /home/${user}/log/sshd/$(date +\%Y\%m\%d_\%H\%M\%S).log

6.参考サイト

Qiita. OpenSSH でログインに使用した公開鍵を記録する. Retrieved May 15, 2018, from https://qiita.com/xtetsuji/items/b5a15f6d1ad3f6091baf
Qiita. ssh鍵の鍵指紋を表示. Retrieved May 15, 2018, from https://qiita.com/matoken/items/c5f2cda7466ab7a2fae6
ウマい話、ちょいくれや。. crontabの設定で日付の入った名前のファイルをつくろうとしたらエラーでたよ. Retrieved May 15, 2018, from http://d.hatena.ne.jp/TamaC/20101014/1287027443

関連記事

コメントを投稿

名前

Email (※公開されることはありません)

コメント