要在Linux中通過SSH加密連接,請按照以下步驟操作:
確保您的系統已安裝了SSH服務器和客戶端。在大多數Linux發行版中,這些組件已經預先安裝。如果沒有,請使用您的包管理器(如apt、yum或pacman)進行安裝。
生成SSH密鑰對(如果尚未生成)。在終端中運行以下命令:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按照提示操作,您可以設置密鑰文件的保存位置和設置密碼保護。建議您為密鑰文件設置一個強密碼。
remote_username、remote_server_ip和your_public_key替換為實際值):ssh-copy-id remote_username@remote_server_ip
如果此命令不可用,您可以手動將公鑰添加到遠程服務器的~/.ssh/authorized_keys文件中:
cat your_public_key.pub | ssh remote_username@remote_server_ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
/etc/ssh/sshd_config文件,確保以下設置已啟用(刪除或注釋掉前面的#):PubkeyAuthentication yes
PasswordAuthentication no
如果您希望允許密碼身份驗證,只需將PasswordAuthentication no更改為PasswordAuthentication yes。但是,這樣做可能會降低安全性,因為任何人都可以使用密碼連接到您的服務器。
sudo systemctl restart sshd
或者
sudo service ssh restart
現在,您應該能夠通過加密連接使用SSH訪問遠程服務器了。在終端中運行以下命令(將remote_username和remote_server_ip替換為實際值):
ssh remote_username@remote_server_ip
輸入密碼后,您將建立加密連接到遠程服務器。