1. 安裝相關套件
sudo apt-get update sudo apt-get install openssh-server
2. 相關設定檔
2.1. sshd_config
/etc/ssh/sshd_config
2.1.1. 安全性設定
# What ports, IPs and protocols we listen for Port 12345
SSH 預設使用 port 22,建議更改,特別在面向網路網路使用時,幾乎只要一上網就會被攻擊。埠號可自定,不要與使用中的埠號即可。
PermitRootLogin prohibit-password
建議不要使用 root 登入 SSH,所以可將 PermitRootLogin 設為 no。但讓 root 能登入有時候滿方便的,特別是有時需要傳一些需要 root 權限的檔案時,可以省掉一些操作上的麻煩。所以這裡使用 prohibit-password,再加上使用免密碼登入方式,就可以讓 root 能登入 SSH,且能保持一定程度的安全性。
#AllowUsers cy # NOTE! this will disable root login
可限定只有某些使用者登入,值得注意的是,若沒有加入 root,將會使 root 不能登入,即使 PermitRootLogin 為 yes 或 prohibit-password 亦然。在我的 Server 並未實作此項,所以前面加 #。
2.1.2. 效能性設定
UseDNS no
加了這個據說能加速登入速度。
3. 資源管理
3.1. 最好不要使用的帳號名
以下為我曾被攻擊的帳號名,最好不要使用這些帳號,特別是 admin:
0 0000 1111 1234 123456 adam adm admin agent anonymous apache bill cisco client customer default edu ftp ftpuser guest jack john manager mark master mike nagios operator oracle osmc pi plcmspip raspberry sales scan service steve super support Taiwan test testuser tiffany ubnt uploader user user1 usuario vyatta www
4. 測試
4.1. ssh 登入測試:
cy@cyvm:~$ ssh -p 12345 cy@192.168.0.1 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. No mail. Last login: Sat Mar 18 11:25:52 2017 from 192.168.0.2
4.2. ssh 登入測試:
cykuo@cyvm:~$ scp -P 12345 -i ~/keys/cy_ssh_key test.file root@192.168.0.1:~/root_work_dir test.file 100% 273 0.3KB/s 00:00
5. 服務管理
安裝完會自動啟動服務,其餘服務常用操作指令如下所列。
systemctl status sshd.service systemctl restart sshd.service systemctl enable sshd.service
沒有留言:
張貼留言