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.