某山寨

z4zr的待调教小窝

CentOS SSH安装及配置

CentOS SSH安装及配置

额 标题有坑啊。。。
默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此。所以就不介绍OpenSSH的安装了。

{
其实很直接的方法:

service sshd start //启动,,,,,

chkconfig sshd on //设置开机启动

执行上面两句 就够了 下面都可以不看了。。。。。
}

Setp1
编辑ssh的配置文件 对于文件的详细配置还是去百度吧。。。
这里没有做过多的安全限制 因为当前机器永远都用不上(目测短命)

# vim /etc/ssh/sshd_config
=======================================================================
# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# 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.

Port 33 ***********这里需要去掉注释 设置ssh的端口号(其实如果没有过多的考虑安全 至修改这个 保存退出即可,后面的设置需要更强大的knowledge)
#AddressFamily any
#ListenAddress 0.0.0.0 ********设置sshd服务器绑定的IP地址(不懂默认即可....)
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

*********************下面这一块可也设置设置私人密匙的文件 更安全
# 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 1024 *************定义服务器密匙的位数

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV ********设置在记录来自sshd的消息的时候,是否给出“facility code”。
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m *******设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位)
#PermitRootLogin yes ********设置root能不能用ssh登录。这个选项一定不要设成“yes”。
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes *********设置是否允许只有RSA安全验证。
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# 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 ******设置ssh daemon是否在进行RhostsRSAAuthentication安全验证的时候忽略用户的“$HOME/.ssh/known_hosts”
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes ***********设置验证的时候是否使用“rhosts”和“shosts”文件。

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no *******设置是否允许用口令为空的帐号登录。
PasswordAuthentication yes ******设置是否允许只有RSA安全验证。

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

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

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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 and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to '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 LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes ***********设置是否允许X11转发。
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes ********设置sshd是否在用户登录的时候显示“/etc/motd”中的信息。
#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 none

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

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server

Step2
修改hosts.deny 在最后面添加一行:
sshd:All
Step3
修改hosts.allow 在最后面添加一行:
sshd:All
Step4
启动SSH
/etc/init.d/sshd start
至此SSH已经可以连接了

这里需要注意 如果开启了防火墙 需要修改防火墙规则哦
将ssh所需要使用的端口开放(默认的22端口 默认防火墙是开放的 如果没有修改端口不需要这一步修改)

vim /etc/sysconfig/iptables

在显示的文件里面 如果有看到22 那么就把22修改为你的端口号
然后保存退出吧,,,,,
然后# service iptables restart 重启防火墙。。。。

然后 用你的SSH软件去连接吧。。。。。

部分系统命令:
开启ssh服务:
service sshd start

关闭ssh服务:
service sshd stop

重启ssh服务:
servcie sshd restart

SSH服务开机自动启动: 额 这句必然需要执行一下啊。。。。。
chkconfig sshd on

取消开机自启动:
chkconfig sshd off

开启服务后,检查服务状态:
service sshd status

More:
不使用私钥的SSH还是有一定风险的......ssh-keygen
PasswordAuthentication no 只允许用户用基于密匙的方式登录
PermitRootLogin without-password 禁止“root”用户登录,只能用“su”命令从普通用户转成“root”

文章二维码