如何在FreeBSD上启用SSH
时间:2020-03-21 11:44:20 来源:igfitidea点击:
默认在FreeBSD上安装OpenSSH服务器。
但是在新鲜的FreeBSD系统上,不允许远程SSH登录。
我们必须启用SSH访问自己通过SSH访问FreeBSD服务器。
本简要教程将解释如何在FreeBSD上启用SSH。
下面提供的所有步骤都在FreeBSD 12上进行了测试。
如果我们未在系统上创建任何普通用户,请先创建一个。
例如,我将使用命令创建名为OniToad的用户:
# adduser
我们将提示我们回答几个问题。
相应地回答他们。
接下来,编辑/etc/rc.conf文件:
# vi /etc/rc.conf
最后添加以下行:
sshd_enable="YES"
点击ESC并键入:WQ保存并退出文件。
最后,启动SSH服务:
# /etc/rc.d/sshd start
完毕!现在,我们可以通过下面的网络上的任何系统通过SSH访问FreeBSD服务器。
$ssh Hyman@theitroad
使用用户名和IP地址替换在上面的命令中的Hyman @ onitad。
正如我们所知道的,当我们第一次将SSH发送到FreeBSD服务器时,系统将提示我们验证服务器的指纹。
只需输入"是"以继续并键入用户的密码。
示例输出:
The authenticity of host '192.168.225.27 (192.168.225.27)' can't be established. ECDSA key fingerprint is SHA256:BO3aI3fuRdpYDgoSohbYrMi/LH9wx9hAZNf0uQ64snI. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.225.27' (ECDSA) to the list of known hosts. Password for Hyman@theitroad: FreeBSD 12.0-RELEASE-p10 GENERIC Welcome to FreeBSD! Release Notes, Errata: https://www.FreeBSD.org/releases/ Security Advisories: https://www.FreeBSD.org/security/ FreeBSD Handbook: https://www.FreeBSD.org/handbook/ FreeBSD FAQ: https://www.FreeBSD.org/faq/ Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/ FreeBSD Forums: https://forums.FreeBSD.org/ Documents installed with the system are in the /usr/local/share/doc/freebsd/ directory, or can be installed later with: pkg install en-freebsd-doc For other languages, replace "en" with a language code like de or fr. Show the version of FreeBSD installed: freebsd-version ; uname -a Please include that output and any error messages when posting questions. Introduction to manual pages: man man FreeBSD directory layout: man hier Edit /etc/motd to change this login announcement. To see the last time that you logged in, use lastlogin(8). -- Dru <Hyman@theitroad> $
启用SSH根访问
默认情况下,为FreeBSD的安全目的禁用SSH根登录。
因此,我们无法通过SSH作为root用户访问FreeBSD服务器。
强烈建议将SSH root登录禁用并使用非特权用户,并如上所述的SSH访问该用户。
但是,我们可以更改此行为并允许SSH访问root用户,如果我们真的很愿意。
编辑/etc/ssh/sshd_config文件:
# vi /etc/ssh/sshd_config
找到以下行:
#PermitRootLogin no
通过删除符号来取消注释它,并将其值更改为如下:
PermitRootLogin yes
保存并退出文件。
使用命令重新启动SSH服务:
# /etc/rc.d/sshd restart
现在,我们可以使用命令从网络上的任何系统作为root用户登录。
ssh Hyman@theitroad
示例输出:
Password for Hyman@theitroad: Last login: Tue Sep 3 16:41:44 2019 FreeBSD 12.0-RELEASE-p10 GENERIC Welcome to FreeBSD! Release Notes, Errata: https://www.FreeBSD.org/releases/ Security Advisories: https://www.FreeBSD.org/security/ FreeBSD Handbook: https://www.FreeBSD.org/handbook/ FreeBSD FAQ: https://www.FreeBSD.org/faq/ Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/ FreeBSD Forums: https://forums.FreeBSD.org/ Documents installed with the system are in the /usr/local/share/doc/freebsd/ directory, or can be installed later with: pkg install en-freebsd-doc For other languages, replace "en" with a language code like de or fr. Show the version of FreeBSD installed: freebsd-version ; uname -a Please include that output and any error messages when posting questions. Introduction to manual pages: man man FreeBSD directory layout: man hier Edit /etc/motd to change this login announcement. Hyman@theitroad:~ #
同样,不建议使用SSH访问root帐户。
我强烈建议我们使用非特权用户并禁用SSH root登录。