ssh无法连接到远端Ubuntu的解决方法
时间: 2016-12-03来源:OSCHINA
前景提要
ssh无法连接到远端Ubuntu的解决方法
2014-10-16 0 个评论 来源:KiteRunner的专栏
收藏 我要投稿
近日,饱受无法远程登录到新安装在VMWare上的Ubuntu虚拟机,如今发现问题所在,故记录此问题的解决方案,以备后用。
一、远程登录虚拟机的准备:
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才能够关闭该接口。
二、关于远端主机(Ubuntu)上的一些配置:
必须安装openssh-server软件,这样才可以通过ssh连接到Ubuntu虚拟机。
安装命令:sudo apt-get install openssh-server.
sudo /etc/init.d/ssh restart(重新启动ssh服务)
具体可参考:Ubuntu下安装OpenSSH Server并在客户端远程连接Ubuntu
现在,安装好openssh-server后,可以运行命令:netstat -an | grep 22 或 ps -e |grep ssh
查看22端口是否处于LISTEN状态或ssh服务是否已经运行,如果是,则说明Ubuntu主机上的ssh已经配置好了。
三、XShell连接到远端主机Ubuntu:
依照提示,逐步配置,端口号选择22,进行个性化配置后,即可进行远程登录。
p.s.
1、为了在xshell中正常的显示中文,我们要把xshell编码方式改成utf8。具体操作为:
[file]–>[open]–>在打开的session中选择连接,点击[properties] -> [Terminal ] ,在右边的translation先选择utf8,然后重新连接服务器即可。
2、如何将windwos上的文件传输到虚拟机上的linux 上
法一:
输入rz –help
如果出现程序“rz”尚未安装。 您可以使用以下命令安装:
sudo apt-get install lrzsz
切换到你要存放文件的目录
File->Transfer->Send ZMODEM,出现一个对话框,选择你要传输的文件就可以了。
法二:
使用pscp(putty的一个绑定程序)来实现文件传输。
另外,个人谈谈采用远程登录方法的一些好处:
1、可以个性化配置终端;
2、虚拟机不必运行在图形界面;
3、操作简单,如同在系统终端上操作一样;
4、传输文件很简单,另外,可以使用粘贴复制,这是很方便的。

附: Fire this command: sudo iptables -L
If 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 ACCEPT
this 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.

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行