scp → sshを使用したファイル転送
認証
パスワード認証:パスワードも暗号化して送られる
鍵認証
ホスト認証:なりすまし防止
sshのサービス確認・起動・停止・再起動
/etc/rc.d/init.d/sshd status /etc/rc.d/init.d/sshd stop /etc/rc.d/init.d/sshd start /etc/rc.d/init.d/sshd restart
sshd.service
$ sudo systemctl status sshd.service $ sudo systemctl stop sshd.service $ sudo systemctl start sshd.service $ sudo systemctl restart sshd.service
設定
設定ファイル:/etc/ssh/sshd_config
※設定を変更したら必ずsshdを再起動する
推奨
Protocol 2 PermitRootLogin no PermitEmptyPasswords no PubkeyAuthentication yes Port 2222 AllowUsers <ユーザ名> ClientAliveInterval 600 ClientAliveCountMax 0 ListenAddress 192.168.1.1
・ssh v2を使う。v1は脆弱性がある為、必ずv2を使うこと。
Protocol 2
・rootでの接続を禁止する
PermitRootLogin no
・パスワード無しのログインを許可しない
PermitEmptyPasswords no
・公開鍵認証の有効化
PubkeyAuthentication yes
・パスワード認証を禁止する
※必ず公開鍵認証の設定を実施してから行う
PasswordAuthentication no
・接続ポート番号を変更する(例:2222)
Port 2222
・接続するユーザを制限する
AllowUsers <ユーザ名>
・アイドル時の自動ログアウト
ClientAliveInterval 600 #ログアウトするまでの時間(秒) ClientAliveCountMax 0
・特定のNIC(IPアドレス)でのアクセス許可 ※sshサーバ側が192.168.1.1
ListenAddress 192.168.1.1
構文チェックコマンド
問題なければなにも表示されない。
/usr/sbin/sshd -t