ssh沒法鏈接到遠端Ubuntu的解決方法php
2014-10-16 0 個評論 來源:KiteRunner的專欄 html
收藏 我要投稿linux
近日,飽受沒法遠程登陸到新安裝在VMWare上的Ubuntu虛擬機,現在發現問題所在,故記錄此問題的解決方案,以備後用。shell
Ubuntu虛擬機的聯網方式應該選擇Bridged(橋接模式),能夠在Ubuntu中配置靜態IP,或者使用路由器(本身使用的是WiFi鏈接,通過無線路由器進行配置)經過DCHP服務器進行IP地址分配(通常配置後再也不改變,經過MAC地址識別來分配地址,除非IP地址已經耗盡)。關於VMWare的幾種聯網方式,能夠參考:vmware中的bridge、nat、host-only的區別服務器
關於配置網卡,可在VMWare的Edit->Virtual Network Editor中進行相關配置。網絡
p.s.在Ubuntu系統中,可使用命令#ifup {interface}和#ifdown {interface}來打開和關閉相關網卡。可是,若是以ifconfig eth0來設置或者是修改了網絡接口後,就沒法再以ifdown eth0的方式來關閉了。由於ifdown會分析比較目前的網絡參數與ifcfg-eth0是否相符,若是不符的話,就會放棄此次操做。所以,使用ifconfig修改完畢後,應該要以ifconfig eth0 down纔可以關閉該接口。session
必須安裝openssh-server軟件,這樣才能夠經過ssh鏈接到Ubuntu虛擬機。app
安裝命令:sudo apt-get install openssh-server.ssh
sudo /etc/init.d/ssh restart(從新啓動ssh服務)tcp
具體可參考:Ubuntu下安裝OpenSSH Server並在客戶端遠程鏈接Ubuntu
如今,安裝好openssh-server後,能夠運行命令:netstat -an | grep 22 或 ps -e |grep ssh
查看22端口是否處於LISTEN狀態或ssh服務是否已經運行,若是是,則說明Ubuntu主機上的ssh已經配置好了。
依照提示,逐步配置,端口號選擇22,進行個性化配置後,便可進行遠程登陸。
p.s.
一、爲了在xshell中正常的顯示中文,咱們要把xshell編碼方式改爲utf8。具體操做爲:
[file]–>[open]–>在打開的session中選擇鏈接,點擊[properties] -> [Terminal ] ,在右邊的translation先選擇utf8,而後從新鏈接服務器便可。
二、如何將windwos上的文件傳輸到虛擬機上的linux 上
法一:
輸入rz –help
若是出現程序「rz」還沒有安裝。 您可使用如下命令安裝:
sudo apt-get install lrzsz
切換到你要存放文件的目錄
File->Transfer->Send ZMODEM,出現一個對話框,選擇你要傳輸的文件就能夠了。
法二:
使用pscp(putty的一個綁定程序)來實現文件傳輸。
另外,我的談談採用遠程登陸方法的一些好處:
一、能夠個性化配置終端;
二、虛擬機沒必要運行在圖形界面;
三、操做簡單,如同在系統終端上操做同樣;
四、傳輸文件很簡單,另外,可使用粘貼複製,這是很方便的。
附:
Fire this command:
sudo iptables -LIf you see that no traffic is allowed (i.e. no specific rules), then run the following command:
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPTthis command tells the system to allow incoming connections to port 22...and usually should solve your dilemma, specifically for
ssh
/sshd
.UPDATED as of July 31,2016: iptables have nothing to do with ssh as an application, but on other hand, functions as router in allow the traffic to port 22. When using iptables, the system actually understand 'ssh' however, it's a shortcut within command line but, really, it's actually
iptables INPUT -p udp -dport 22
while --dport means "destination port" (ssh uses port 22). This probably caused some misconception on seeing 'ssh' as if it's an appication, but really '22' as port.