首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux 有没有办法禁止root直接登录,该怎么解决

2012-12-18 
linux 有没有办法禁止root直接登录而是如果需要root的时候用su命令登陆。[最优解释]如果是远程利用ssh登录

linux 有没有办法禁止root直接登录
而是如果需要root的时候用su命令登陆。
[最优解释]
如果是远程利用ssh登录的话
修改/etc/ssh/sshd_config文件

PermitRootLogin yes
改成
PermitRootLogin no
重启sshd
[其他解释]

引用:
如果是远程利用ssh登录的话
修改/etc/ssh/sshd_config文件

PermitRootLogin yes
改成
PermitRootLogin no
重启sshd


我照你的方法做了,不过导致别的账号也无法登陆了,我将参数改回yes,重启sshd,不生效了!

无论用什么账号登陆 /var/log/secure 中都会显示 
refused connect from ::ffff:ip地址
[其他解释]
引用:
我照你的方法做了,不过导致别的账号也无法登陆了,我将参数改回yes,重启sshd,不生效了!

无论用什么账号登陆 /var/log/secure 中都会显示 
refused connect from ::ffff:ip地址

杯具了
除非你把设定文件修改错了  或者更改了别的地方
或者你曾经修改过设定文件 修改错误了  但是没有重启过  今天重启恰好生效了
否则单改PermitRootLogin no 不会造成这样的情况
这一句只是否运行root用户远程登录有关  不信你可以看看sshd_config配置手册
http://www.svn8.com/shouce/OpenSSH/sshd_config.html
[其他解释]
是不是当有远程ip连接到sshd服务上的时候,sshd服务无法重启?
[其他解释]
引用:
是不是当有远程ip连接到sshd服务上的时候,sshd服务无法重启?

可以重启啊 
你在检查一下你的sshd_config文件
修改之前备份了吗  对比一下修改前和修改后的区别
[其他解释]
重启sshd时,
/var/log/secure 中总出现:
Jun 29 15:09:54 localhost sshd[27932]: Server listening on :: port 22.
Jun 29 15:09:54 localhost sshd[27932]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

我将端口改为 39 则出现:
Jun 29 15:09:54 localhost sshd[27932]: Server listening on :: port 39.
Jun 29 15:09:54 localhost sshd[27932]: error: Bind to port 39 on 0.0.0.0 failed: Address already in use.
[其他解释]
重启sshd时,
/var/log/secure 中总出现:
Jun 29 15:09:54 localhost sshd[27932]: Server listening on :: port 22.
Jun 29 15:09:54 localhost sshd[27932]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
-----------------------------
别随便修改端口  你是如何重启的
用root执行如下命令 看看是哪个程序在使用22号端口
/usr/sbin/lsof -i tcp:22

如果本来就是sshd的话 就说明你的重启方法是错误的
[其他解释]
引用:
重启sshd时,
/var/log/secure 中总出现:
Jun 29 15:09:54 localhost sshd[27932]: Server listening on :: port 22.
Jun 29 15:09:54 localhost sshd[27932]: error: Bind to port 22 on 0.0.0.0 failed: Address alrea……


[root@mail ~]# lsof -i tcp:22
COMMAND   PID USER   FD   TYPE    DEVICE SIZE NODE NAME
sshd    28216 root    3u  IPv6 371977901       TCP *:ssh (LISTEN)



没错,就是sshd.

我启动就是用 service sshd start 来启动。
[其他解释]

现在问题不在重启上
我怀疑你把sshd_config改坏了
我不是让你检查一下吗  看5楼
[其他解释]

引用:
没错,就是sshd.

我启动就是用 service sshd start 来启动。

直接service sshd reload就可以了
现在关键是你要确认检查一下你的sshd_config文件!

如果程序正在运行 修改完设定文件 service sshd reload就可以了
[其他解释]
好的 熊猫兄弟
[其他解释]
引用:
引用:


没错,就是sshd.

我启动就是用 service sshd start 来启动。

直接service sshd reload就可以了
现在关键是你要确认检查一下你的sshd_config文件!

如果程序正在运行 修改完设定文件 service sshd reload就可以了


好, 等我把服务器重启后,仔细对比
[其他解释]
还有就是,我从内网别的机器用 ssh命令可以连接上。
外网则私活不行,防火墙也没动!
[其他解释]
引用:
还有就是,我从内网别的机器用 ssh命令可以连接上。
外网则私活不行,防火墙也没动!

 netstat -tnl 
[其他解释]
 grep 22
的结果 给我看看
[其他解释]
引用:
引用:

还有就是,我从内网别的机器用 ssh命令可以连接上。
外网则私活不行,防火墙也没动!

 netstat -tnl 
[其他解释]
 grep 22
tcp        0      0 :::22                       :::*                        LISTEN     
[其他解释]
 grep 22
的结果 给我看看


[root@mail /]# netstat -tnl 
[其他解释]
 grep 22  
tcp        0      0 :::22                       :::*                        LISTEN      3400/sshd  

[其他解释]

netstat -tnlp 
[其他解释]
引用:
也没问题  对比设定文件了么?


:::22 和 :::* 这样正确吗?

我看别的服务时,前边都有几个0啊:

[root@mail /]# netstat -tnlp 
------其他解决方案--------------------


也没问题  对比设定文件了么?
[其他解释]
我快要郁闷死了
我就让你改了PermitRootLogin no这个配置
怎么引出这么多问题哇!
[其他解释]
 grep 25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      3786/master 


[其他解释]
/etc/ssh/sshd_config 的内容如下:
该改的已经改回去了,仔细对比,没有啥异样啊!


#Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile     .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no

#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication mechanism.
# Depending on your PAM configuration, this may bypass the setting of
# PasswordAuthentication, PermitEmptyPasswords, and
# "PermitRootLogin without-password". If you just want the PAM account and


# session checks to run without PAM authentication, then enable this but set
# ChallengeResponseAuthentication=no
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
#AllowTcpForwarding yes
#GatewayPorts no

#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server


[其他解释]
:::22 和 :::* 这样正确吗
----
正确  因为配置文件里#AddressFamily any 是默认
所以sshd会在ipv4和ipv6上同时监听

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      3786/master 
这个只是在ipv4上监听
[其他解释]
现在到底是什么状况?
内网能用ssh连上?
通过公网ip不能连上?
是吗

PermitRootLogin yes
改成
PermitRootLogin no
之后
内网还能通过root访问吗?
[其他解释]
引用:
我快要郁闷死了
我就让你改了PermitRootLogin no这个配置
怎么引出这么多问题哇!



呵呵,是啊是啊,熊猫兄弟请海涵,事后一定加100分!
出现别的问题,正好向你学习学习解决思路!
[其他解释]
引用:
现在到底是什么状况?
内网能用ssh连上?
通过公网ip不能连上?
是吗


是的,通过内网依然能访问,但公网不行。





[其他解释]
还有 看样子你是服务器 这样的信息别直接贴出来 可以站内短信发给我
[其他解释]
又改回了 PermitRootLogin yes,还是那个密码,就能等上!
[其他解释]
引用:
PermitRootLogin yes
改成
PermitRootLogin no
之后
内网还能通过root访问吗?



改成 no后,通过内网访问失败:
让输入三次密码,三次后就拒绝了!
[其他解释]
引用:
引用:

引用:



PermitRootLogin yes
改成
PermitRootLogin no
之后
内网还能通过root访问吗?



改成 no后,通过内网访问失败:


让输入三次密码,三次后就拒绝了!

是root用户被拒绝了
还是普通用户也无法访问?



root被拒绝了,普通用户可以登录!也就是该参数在内网达到了目的了!
[其他解释]
引用:
引用:

又改回了 PermitRootLogin yes,还是那个密码,就能等上!

你是指root用户 还是普通用户
 PermitRootLogin no 就是不让root用户登录

在PermitRootLogin yes的情况下,内网连接,无论root还是普通都能登录!

[其他解释]
引用:
引用:



PermitRootLogin yes
改成
PermitRootLogin no
之后
内网还能通过root访问吗?



改成 no后,通过内网访问失败:
让输入三次密码,三次后就拒绝了!

是root用户被拒绝了
还是普通用户也无法访问?
[其他解释]
引用:
又改回了 PermitRootLogin yes,还是那个密码,就能等上!

你是指root用户 还是普通用户
 PermitRootLogin no 就是不让root用户登录
[其他解释]
引用:
你确认一下防火墙  我觉得是防火墙禁止外网连接22号端口?


防火墙查过了,没问题!
而且我在远程用telnet ip_address 22 试过了
能够连接上,而非直接不让连接的现象!


[其他解释]
引用:
用公网不能连接的错误信息时什么啊


用secureCRT连接,就是半天没反应!

之后在服务器上查看 /var/log/secure文件,就会有如下错误记录:
Jun 29 13:50:12 localhost sshd[25809]: refused connect from ::ffff:122.116.123.106 (::ffff:122.116.123.106)
[其他解释]
你确认一下防火墙  我觉得是防火墙禁止外网连接22号端口?
[其他解释]
用公网不能连接的错误信息时什么啊
[其他解释]
我下班了 先回家了 
一会到家了 再讨论
[其他解释]
试了, 远程还是无法登陆!
[其他解释]
修改之前先备份
把设定文件里的
#AddressFamily any
改成 井号去掉
AddressFamily inet

然后service sshd restart
载测试一下
[其他解释]
引用:
修改之前先备份
把设定文件里的
#AddressFamily any
改成 井号去掉
AddressFamily inet

然后service sshd restart
载测试一下


嗯,下次一定注意! 
[其他解释]
引用:
除了防火墙iptables 你还设置/etc/hosts.allow 和/etc/hosts.deny 文件了吗


好了,现在可以了,熊猫兄弟! 
果然是/etc/hosts.deny的问题,我装了一个denyhost 防暴力破解!

denyhost把我们公司的公网ip添加到这个文件里,导致无法访问!
这跟sshd本身的设置没有一点关系!
[其他解释]
非常感谢,额外加100分!

熊猫兄弟在北京吗? 如在周末找我骑行妙峰山,我请客,以表达我的感激之情!


[其他解释]
引用:
我下班了 先回家了 
一会到家了 再讨论


好的 熊猫兄弟,真仗义,即便没解决的话,也学了不少东西!

[其他解释]
除了防火墙iptables 你还设置/etc/hosts.allow 和/etc/hosts.deny 文件了吗

热点排行
Bad Request.