ubuntu20設置ssh遠程連接
1.安裝openssh-server
打開終端安裝openssh-server軟件包:
sudo apt update # 更新包
sudo apt install openssh-server # 安裝openssh-server
2.查看ssh狀態
安裝完成后,ssh服務默認啟動了,可以通過下面的命令檢查服務運行狀態:
sudo systemctl status ssh

3.防火墻開啟ssh端口
Ubuntu 默認使用 ufw 防火墻配置工具,如果啟用了防火墻,需要讓防火墻開啟ssh端口:
sudo ufw allow ssh

4.配置允許root遠程ssh登錄訪問
使用sudo權限,編輯ssh的配置文件。
sudo vim /etc/ssh/sshd_config

將#PermitRootLogin prohibit-password中prohibit-password去掉改為yes,并把PermitRootLogin yes之前的#去掉,即PermitRootLogin yes
重啟ssh服務
systemctl sshd restart

4.連接ssh服務
通過網絡連接到 Ubuntu 計算機,請使用以下格式調用 ssh 命令,然后輸入用戶名和IP地址:
ssh root@192.168.79.131
首次連接時會看到以下內容(192.168.79.131是需要被ssh遠程訪問的IP地址,是內網IP地址)
The authenticity of host '192.168.79.131 (192.168.79.131)' can't be established. ECDSA key fingerprint is SHA256:AqAuoVjwoRuoiFCZ6tdDmIZBvixrHZn4ykzHkB+wVb8. Are you sure you want to continue connecting (yes/no/[fingerprint])?
輸入yes后按回車鍵,提示輸入密碼。
Warning: Permanently added '192.168.79.131' (ECDSA) to the list of known hosts. ubuntu20@192.168.79.131's password:
正確輸入密碼后,連接建立。
5.ssh服務的啟用與禁用
sudo systemctl disable --now ssh # 禁用服務
sudo systemctl enable --now ssh # 啟用服務

浙公網安備 33010602011771號