天天看點

Ubuntu下開啟SSH

轉自:https://www.aliyun.com/jiaocheng/134508.html

https://www.cnblogs.com/CGDeveloper/archive/2011/07/27/2118533.html

摘要:windows下的VMwareStation安裝了ubuntu(版本不限)。想通過遠端工具WinSCP上傳檔案,因為U盤挂載的辦法太麻煩了。打開WinSCP程式,輸入需要的資訊,連接配接。顯示“連接配接由于目标計算機積極拒絕,無法連接配接。”我懷疑遠端服務沒開啟。開啟遠端伺服器在終端界面輸入:servicesshdstart。結果顯示:ssh:unrecognizedservice。輸入檢視指令:servicesshstatus顯示也是unrecognizedservice。這個時候察覺windows下的VMware Station安裝了ubuntu(版本不限)。想通過遠端工具WinSCP上傳檔案,因為U盤挂載的辦法太麻煩了。 打開WinSCP程式,輸入需要的資訊,連接配接。 顯示“連接配接由于目标計算機積極拒絕,無法連接配接。” 我懷疑遠端服務沒開啟。

開啟遠端伺服器

在終端界面輸入:service sshd start。

結果顯示:ssh:unrecognized service。

Ubuntu下”sshd:unrecognized service”

輸入檢視指令: service ssh status

顯示也是 unrecognized service。

Ubuntu下”sshd:unrecognized service”

這個時候察覺,沒有開啟ssh服務。

開啟ssh服務:

終端界面鍵入:sudo /etc/init.d/ssh restart

(或sudo /etc/init.d/ssh start)

SSH分用戶端openssh-client和openssh-server

如果你隻是想登陸别的機器的SSH隻需要安裝openssh-client(ubuntu有預設安裝,如果沒有則sudo apt-get install openssh-client),如果要使本機開放SSH服務就需要安裝openssh-server

sudo apt-get install openssh-server

然後确認sshserver是否啟動了:

ps -e |grep ssh

如果看到sshd那說明ssh-server已經啟動了。

如果沒有則可以這樣啟動:sudo /etc/init.d/ssh start

ssh-server配置檔案位于/ etc/ssh/sshd_config,在這裡可以定義SSH的服務端口,預設端口是22,你可以自己定義成其他端口号,如222。

然後重新開機SSH服務:

sudo /etc/init.d/ssh stop

sudo /etc/init.d/ssh start

windows下使用SSH軟體登入Ubuntu root使用者時會出錯,解決方法:

編輯ssh的配置檔案etc/ssh/sshd_config

在Authentication部分,注釋掉“PermitRootLogin without-password”

在Authentication部分,添加“PermitRootLogin yes”

然後重新開機ssh服務。

這樣就可以通過ssh工具遠端登入了。

繼續閱讀