FreeBSD下面配置SSH服务,共要修改三个文件,这三个文件目录分别为:
1、inetd.conf /etc/inetd.conf
2、rc.conf /etc/rc.conf
3、sshd_config /etc/ssh/sshd_config
修改文件配置:
1、修改vi /etc/inetd.conf文件
#ssh stream tcp nowait root /usr/sbin/sshd sshd -i -4
#ssh stream tcp6 nowait root /usr/sbin/sshd sshd -i -6
把第一条前面的#删除掉,你若想同时使用IP v6,把第二条前面的#也删除掉,保存退出。
使用命令查看修改后的效果:
freebsd# cat /etc/inetd.conf | grep ssh
ssh stream tcp nowait root /usr/sbin/sshd sshd -i -4
#ssh stream tcp6 nowait root /usr/sbin/sshd sshd -i -6
freebsd#
2、修改vi /etc/rc.conf文件,在文件最后,添加上:
sshd_enable=”YES”
保存退出。
3、修改vi /etc/ssh/sshd_config文件的如下内容
第19行 Port 22 #注:看网上的教程没有开启19、20行,但我开启了。
第20行 Protocol 2
第42行 PermitRootLogin yes #注:不建议开启此项,远程使用root直接登录,有一定的危险性。
第43行 StrictModes yes
第46行 RSAAuthentication yes
第56行 IgnoreUserKnownHosts no
第58行 IgnoreRhosts yes
第61行 PasswordAuthentication yes
第62行 PermitEmptyPasswords no
第92行 PrintMotd yes
其它内容根据自己的需要打开或关闭,保存退出。
下面是我本机修改过的内容
=========================================================================
# $OpenBSD: sshd_config,v 1.72 2005/07/25 11:59:40 markus Exp $
# $FreeBSD: src/crypto/openssh/sshd_config,v 1.42.2.1 2005/09/11 16:50:35 des Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
# Note that some of FreeBSD’s defaults differ from OpenBSD’s, and
# FreeBSD has a few additional options.
#VersionAddendum FreeBSD-20050903
Port 22
#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_dsa_key
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768
# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#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
# Don’t read the user’s ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# Change to yes to enable built-in password authentication.
PasswordAuthentication yes
PermitEmptyPasswords no
# Change to no to disable PAM authentication
#ChallengeResponseAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
# Set this to ‘no’ to disable 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 yes
#AllowTcpForwarding yes
#GatewayPorts 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
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
# no default banner path
#Banner /some/path
# override default of no subsystems
Subsystem sftp /usr/libexec/sftp-server
=========================================================================
3、启动服务查看SSH 22端口是否在监听状态下
启动SSH服务
freebsd#/etc/rc.d/sshd start
重新启动SSH服务
freebsd#/etc/rc.d/sshd restart
查看SSH服务端口是否开启
freebsd# netstat -na | grep 22
tcp4 0 52 192.168.1.250.22 192.168.1.88.18134 ESTABLISHED
tcp4 0 0 *.22 *.* LISTEN
tcp6 0 0 *.22 *.* LISTEN
freebsd#
配置完成。接下来你就可以不用再坐在freebsd主机面前了,使用SSH工具就能远程连接freebsd主机了。
如果你在配置中遇到问题请留言。
评论