Linux中SSHD配置文件详解

小柒博客 Linux1 96.6K4字数 4598阅读15分19秒阅读模式

SSH简介

ssh(Secure Shell :安全外壳协议)

由 IETF 的网络工作小组(Network Working Group)所制定。

SSH 为建立在应用层和传输层基础上的安全协议。

SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。

ssh结构 :ssh和sshd

客户端:scp(远程拷贝)、slogin(远程登陆)、sftp(安全文件传输)。

服务器端:公共密钥认证、密钥交换、对称密钥加密、非安全连接。

服务器配置文件详解 :/etc/ssh/sshd_conf

Port 22                   //端口号

//sshd服务器绑定的IP地址

#AddressFamily any

#ListenAddress10.105.120.221

//sshd版本2

Protocol 2

//设置包含计算机私人密匙的文件

#HostKey /etc/ssh/ssh_host_rsa_key

#HostKey/etc/ssh/ssh_host_dsa_key

//定义服务器密匙的位数

# Lifetime andsize of ephemeral version 1 server key

#KeyRegenerationInterval1h

#ServerKeyBits1024

//日志

# Logging

# obsoletesQuietMode and FascistLogging

#SyslogFacilityAUTH

SyslogFacilityAUTHPRIV             //日志Facility为AUTHPRIV

#LogLevel INFO                           //日志级别

# Authentication:

#LoginGraceTime 2m                  //表示认证的时限(以秒为单位)

#PermitRootLoginyes                 //root能不能用ssh登录

#StrictModes yes                        //ssh在接收登录请求之前是否检查用户家目录和rhosts文件的权限和所有权

#MaxAuthTries 6                        //只允许输错几回密码

#MaxSessions 10                        //最大支持几个ssh会话

//密钥认证

RSAAuthenticationyes               //是否使用RSA算法进行安全验证

PubkeyAuthenticationyes         //支持密钥的方式连接

AuthorizedKeysFile       .ssh/authorized_keys      //密钥文件存放路径

#AuthorizedKeysCommandnone

#AuthorizedKeysCommandRunAsnobody

//主机验证

# For this to workyou will also need host keys in /etc/ssh/ssh_known_hosts

#RhostsRSAAuthenticationno              //版本1使用的

# similar forprotocol version 2

#HostbasedAuthenticationno

# Change to yes ifyou don't trust ~/.ssh/known_hosts for

#RhostsRSAAuthentication and HostbasedAuthentication

#IgnoreUserKnownHostsyes

# Don't read theuser's ~/.rhosts and ~/.shosts files

#IgnoreRhosts yes

//口令验证

# To disabletunneled clear text passwords, change to no here!

#PasswordAuthenticationno              //是否开启身份验证

#PermitEmptyPasswordsno                //是否允许用口令为空的帐号登录

PasswordAuthenticationno                //是否使用口令验证

//是否开启挑战响应身份验证

# Change to no todisable s/key passwords

#ChallengeResponseAuthenticationyes

ChallengeResponseAuthenticationno

//Kerberos身份验证

# Kerberos options

#KerberosAuthenticationno

#KerberosOrLocalPasswdyes

#KerberosTicketCleanupyes

#KerberosGetAFSTokenno

#KerberosUseKuserokyes

//GSSAPI是公共安全事务应用程序接口(GSS-API)

//公共安全事务应用程序接口以一种统一的模式为使用者提供安全事务,由于它支持最基本的机制和技术,所以保证不同的应用环境下的可移植性.该规范定义了GSS-API事务和基本元素,并独立于基本的机制和程序设计语言环境,并借助于其它相关的文档规范实现.

# GSSAPI options

#GSSAPIAuthenticationno                   //是否允许使用基于GSSAPI 的用户认证.默认值为"no".仅用于SSH-2

GSSAPIAuthenticationyes

#GSSAPICleanupCredentialsyes          //是否在用户退出登录后自动销毁用户凭证缓存。

GSSAPICleanupCredentialsyes

#GSSAPIStrictAcceptorCheckyes

#GSSAPIKeyExchangeno

//SSH服务端的的PAM认证

# Set this to'yes' to enable PAM authentication, account processing,

# and sessionprocessing. If this is enabled, PAM authentication will

# be allowedthrough the ChallengeResponseAuthentication and

#PasswordAuthentication.  Depending on yourPAM configuration,

# PAMauthentication via ChallengeResponseAuthentication may bypass

# the setting of"PermitRootLogin without-password".

# If you just wantthe PAM account and session checks to run without

# PAMauthentication, then enable this but set PasswordAuthentication

# andChallengeResponseAuthentication to 'no'.

#UsePAM no

UsePAM yes                     //是否加载/etc/pam.d/sshd

//指定客户端发送的哪些环境变量将会被传递到会话环境中

# Acceptlocale-related environment variables

AcceptEnv LANGLC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

AcceptEnv LC_PAPERLC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT

AcceptEnvLC_IDENTIFICATION LC_ALL LANGUAGE

AcceptEnvXMODIFIERS

//转发

#AllowAgentForwardingyes

//如果采用本地转发方式,AllowTcpForwarding选项是no,则不允许转发.

//如果采用远程转发方式,AllowTcpForwarding选项是no,则不允许转发.

#AllowTcpForwardingyes

//远程主机连接本地转发端口

#GatewayPorts no              //是否允许远程主机连接本地的转发端口

//X11转发允许在 SSH 客户端上显示应用程序的图形部分,而程序逻辑依然在远程服务器上执行.

#X11Forwarding no

X11Forwarding yes

#X11DisplayOffset10

#X11UseLocalhostyes

//允许或禁止登陆用户、组

AllowUsers 用户

AllowGroups 组

DenyUsers

DenyGroups

#PrintMotd yes                           //登录后显示/etc/motd中的信息

#PrintLastLog yes                       //成功登录后显示最后一位用户的登录信息

TCPKeepAlive yes                       //是否持续发送tcp包,维持连接

#UseLogin no //是否使用ssh服务端的login程序进行登录验证

#UsePrivilegeSeparationyes       //SSH服务端通过创建非特权子进程处理接入请求的方法来进行权限分离

#PermitUserEnvironmentno

#Compressiondelayed                //压缩选项yes

//连接超时断开连接

#ClientAliveInterval0                  //设置一个以秒记的时长,如果超过这么长时间没有收到客户端的任何数据,sshd 将通过安全通道向客户端发送一个"alive"消息,并等候应答.

#ClientAliveCountMax3            //sshd在未收到任何客户端回应前最多允许发送多少个"alive"消息,到达这个上限后,sshd 将强制断开连接,关闭会话

#ShowPatchLevel no                //在连接ssh端口时,是否返回SSH的补丁版本信息

UseDNS no    //是否对远程主机名进行反向解析,以检查此主机名是否与其IP地址真实对应.

#PidFile/var/run/sshd.pid          //pid文件存放位置

//这个选项一定要配合LoginGraceTime选项一起使用.

#MaxStartups10:30:100            //允许有多少次验证连接请求

#PermitTunnel no

#ChrootDirectorynone

# no defaultbanner path

#Banner none                          //登录之前显示在用户屏幕上,后面跟着文件位置

//配置一个外部的子系统,仅用于SSH-V2协议,一般这里使用sftp

# override defaultof no subsystems

Subsystem      sftp  /usr/libexec/openssh/sftp-server

# Example ofoverriding settings on a per-user basis

#Match Useranoncvs

#     X11Forwarding no

#     AllowTcpForwarding no

#     ForceCommand cvs server

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
Linux最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2018年12月24日11:49:54
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/1714.html
    • 运维老司机
      运维老司机 6

      亲测,写的不错,感谢博主 :razz:

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    拖动滑块以完成验证