- 安裝和配置ssh:
- 在Ubuntu上安裝SSH服務(wù):sudo apt update && sudo apt install openssh-server。
- 啟動(dòng)和檢查SSH服務(wù)狀態(tài):sudo systemctl start ssh 和 sudo systemctl status ssh。
- 修改SSH端口以增強(qiáng)安全性:編輯 /etc/ssh/sshd_config 文件,例如添加 Port 2222 然后重啟SSH服務(wù):sudo systemctl restart ssh。
- 連接到遠(yuǎn)程服務(wù)器:
- 基本連接命令:ssh username@ip_address。
- 指定端口號(hào)連接:ssh -p port_number username@ip_address。
- 使用密鑰登錄以提高安全性:生成密鑰對:ssh-keygen -t rsa,上傳公鑰到遠(yuǎn)程服務(wù)器:ssh-copy-id username@ip_address。
- SSH命令使用技巧:
-
使用 scp 進(jìn)行安全的文件傳輸:
- 從本地復(fù)制到遠(yuǎn)程:scp /path/to/local/file username@ip_address:/path/to/remote/destination。
- 從遠(yuǎn)程復(fù)制到本地:scp username@ip_address:/path/to/remote/file /path/to/local/destination。
-
斷開SSH連接:exit。
- 提高SSH連接的安全性和效率:
- 禁用root登錄:在 /etc/ssh/sshd_config 中設(shè)置 PermitRootLogin no。
- 使用非標(biāo)準(zhǔn)端口:修改SSH配置文件中的端口設(shè)置,以減少被自動(dòng)掃描的風(fēng)險(xiǎn)。
- 啟用公鑰認(rèn)證并禁用密碼認(rèn)證:在SSH配置文件中設(shè)置 PubkeyAuthentication yes 和 PasswordAuthentication no。
- 定期更換SSH密鑰:降低密鑰被盜用的風(fēng)險(xiǎn)。
- 其他技巧:
- 使用 ufw 允許SSH流量:sudo ufw allow ssh。
- 查看SSH服務(wù)狀態(tài):sudo systemctl status ssh。
通過以上技巧,可以更高效和安全地使用Ubuntu的SSH命令行功能。