FreeBSD允许root用户通过SSH登陆

发布时间 2023-08-28 16:30:11作者: Youbin

因为安全原因,安装完FreeBSD后默认是不允许root用户通过SSH协议进行远程登录的,但是我们可以手动配置开启它。

1、修改inetd.conf文件

打开文件/etc/inetd.conf并找到ssh两行,然后把注释去掉保存,如下:

# $FreeBSD$
#
# Internet server configuration database
#
# Define *both* IPv4 and IPv6 entries for dual-stack support.
# To disable a service, comment it out by prefixing the line with '#'.
# To enable a service, remove the '#' at the beginning of the line.
#
#ftp    stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -l
#ftp    stream  tcp6    nowait  root    /usr/libexec/ftpd       ftpd -l
ssh     stream  tcp     nowait  root    /usr/sbin/sshd          sshd -i -4
ssh     stream  tcp6    nowait  root    /usr/sbin/sshd          sshd -i -6
#telnet stream  tcp     nowait  root    /usr/libexec/telnetd    telnetd
#telnet stream  tcp6    nowait  root    /usr/libexec/telnetd    telnetd
#shell  stream  tcp     nowait  root    /usr/local/sbin/rshd    rshd
#shell  stream  tcp6    nowait  root    /usr/local/sbin/rshd    rshd
#login  stream  tcp     nowait  root    /usr/local/sbin/rlogind rlogind
#login  stream  tcp6    nowait  root    /usr/local/sbin/rlogind rlogind
#finger stream  tcp     nowait/3/10 nobody /usr/libexec/fingerd fingerd -k -s
#finger stream  tcp6    nowait/3/10 nobody /usr/libexec/fingerd fingerd -k -s
#
# run comsat as root to be able to print partial mailbox contents w/ biff,
# or use the safer tty:tty to just print that new mail has been received.
#comsat dgram   udp     wait    tty:tty /usr/libexec/comsat     comsat
...略

2、修改sshd_config文件

注意:这里是sshd_config而不是ssh_config文件。

打开文件/etc/ssh/sshd_config并找到PermitRootLogin这一行,然后把注释去掉保存,如下:

.....
# Authentication:

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

#PubkeyAuthentication yes
.....

3、重启sshd服务

方式1:

service sshd restart

方式2:

/etc/rc.d/sshd restart