菜到半夜写作业

查询远程连接断开的问题所在

通过在互联网上,一些大神提供了检查思路:
1、ifconfig网卡是否正常启动;
2、防火墙是否挡住远程的端口
3、sshd服务是否正常启动

一、网卡是否正常启动

1、在在终端上输入命令:ifconfig -a
·有没有网卡?
2、在终端上输入命令:ifconfig
·检查网卡是否up上了?
·ip有没得?
3、
·有网卡,但没启动,在终端上输入命令:ifconfig 网卡名 up (关闭则把up换为down)
如果这个命令不行,换为:ip link set 网卡名 up (关闭则把up换为down)
·没有ip,在终端上输入命令:sudo dhclient 网卡名 (让系统自己分配ip)

二、网卡的配置文件进行挂起和分配ip

配置过程:
1、打开Ubuntu的/etc/network/interfaces文件,vim /etc/network/interfaces
默认内容如下:
auto lo
iface lo inet loopback

2、eth0为自动获取IP,所以不需要配置了。插入要手工设置IP的eth1的IP信息,编辑后内容如下,前面auto eth1,让网卡开机自动挂载.:
auto lo
iface lo inet loopback

#开机自动连接网络
auto eth1
#static表示使用固定ip,dhcp表述使用动态ip
iface eth1 inet static
address 192.168.0.101
netmask 255.255.255.0
network 192.168.0.0
broadcask 192.168.0.255
gateway 192.168.0.2
hwaddress ether [your_mac_address] (让网络配置帮顶到某张物理mac网卡上)

3、编写完毕保存,然后打开终端运行如下命令,重新启动网卡即可:
/etc/init.d/networking restart
也可以重启网卡让新配置生效,优点是不影响其他网络接口:
sudo ifdown eth0
sudo ifup eth0

4、如果以DHCP方式配置网卡(自动分配地址),则改为:
auto eth0
iface eth0 inet dhcp

也可以在命令行下直接输入下面的命令来获取地址(即中所示)
sudo dhclient eth0

三、关闭防火墙

1、查看firewall服务状态
systemctl status firewalld
出现Active: active (running)切高亮显示则表示是启动状态。
出现 Active: inactive (dead)灰色表示停止,看单词也行。

2、我们这里选择关闭防火墙
开启:
service firewalld start
重启:
service firewalld restart
关闭:
service firewalld stop

四、开启SSH服务

1、查看ssh服务是否启动
ps -e|grep ssh
或者是sudo service ssh status

2、设置开机自启ssh服务:
sudo systemctl enable ssh (enable 换为disable 即关闭ssh服务)
但系呢,我这条命令用不了,真的奇怪,
所以我使用了:
sudo systemctl start ssh
或者是sudo systemctl start sshd
或者是sudo /etc/init.d/ssh start (start 换为stop即关闭ssh服务)
或者是sudo service ssh start
或者是sudo service sshd start 但是这条命令不能开机自启动,
所以我不得不在根目录下创建vim .bashrc文件写入sudo service ssh start使之开机自启动。

3、有的时候需要修改配置文件
使用vim /etc/ssh/sshd_config进入,将PermitRootLogin设置为yes,之后
systemctl restart sshd进行重启。
同时看看端口是不是开放的,默认Port 22

备注:PermitRootLogin 配置详解
Specifies whether root can log in using ssh(1). The argument must be “yes”,
“without-password”, “forced-commands-only”, or “no”. The default is “yes”.
If this option is set to “without-password”, password authentication is disabled for root.
If this option is set to “forced-commands-only”, root login with public key authentication
will be allowed, but only if the command option has been specified (which may be useful for taking remote backups even if root login is normally not allowed). All other authentication methods are disabled for root. If this option is set to “no”, root is not allowed to log in.

4、其他人的报错
ssh无法远程连接ubuntu系统,提示"System is booting up. See pam_nologin(8)"
在这里插入图片描述

5、当时傻逼输入
关闭一个服务:sudo systemctl stop sshd
还是 设定服务开机不启动: sudo systemctl disable sshd
直接把连接ssh服务的link给我删了
我当场心肌梗塞 想删了ssh重新下载来着 还好没这么做
输入:
开启一个服务 :sudo systemctl start ssh
开启一个服务 :sudo systemctl start sshd
重启一个服务:sudo systemctl restart ssh
重启一个服务:sudo systemctl restart sshd
设定一个服务开机启动:sudo systemctl enable ssh
设定一个服务开机启动: sudosystemctl enable sshd
都无济于事
最终输入:sudo systemctl start ssh.service
或者是 sudo systemctl start sshd.service
才重新link上了。

下次再出错,可以试试,
重新加载服务的配置文件: systemctl reload sshd
或者是systemctl reload ssh
这个命令。

所以,ssh和sshd有啥区别?
总的来说,检查错误得一步一步来,急也没用,没用也急–555, 千万别乱删东西!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值