ssh配置含义解释
ssh包括客户端配置(ssh_config)和服务端配置(sshd_config)
一、客户端配置ssh_config,客户端软件有SecureCRT、putty、Xshell等
“#”表示注释,虽然表示不起作用,但有时说明此为系统默认的初始化设置
# $OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm Exp $ # This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line. # Configuration data is parsed as follows:
# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end. # Site-wide defaults for some commonly used options. For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page. "Host"只对匹配后面字串的计算机有效,“*”表示所有的计算机。从该项格式前置一些可以看出,这是一个类似于全局的选项,表示下面缩进的选项都适用于该设置,可以指定某计算机替换*号使下面选项只针对该算机器生效。
# Host *
设置连接是否经过验证代理(如果存在)转发给远程计算机
# ForwardAgent no
置X11连接是否被自动重定向到安全的通道和显示集(DISPLAY set)
# ForwardX11 no
设置是否使用用RSA算法的基于rhosts的安全验证
# RhostsRSAAuthentication no
设置是否使用RSA算法进行安全验证
# RSAAuthentication yes
设置是否使用口令验证
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# GSSAPITrustDNS no
批处理模式,一般设为"no";如果设为"yes",交互式输入口令的提示将被禁止,这个选项对脚本文件和批处理任务十分有用
# BatchMode no
设置ssh是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设置为"yes"。
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
如果设为"yes",ssh将不会自动把计算机的密匙加入"$HOME/.ssh/known_hosts"文件,且一旦计算机的密匙发生了变化,就拒绝连接
# StrictHostKeyChecking ask
设置读取用户的RSA安全验证标识
# IdentityFile ~/.ssh/identity
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
设置连接到远程主机的端口,ssh默认端口为22
# Port 22
# Protocol 2,1
设置加密用的密钥,blowfish可以自己随意设置
# Cipher 3des
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
设置escape字符
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
Host *
GSSAPIAuthentication yes
# If this option is set to yes then remote X11 clients will have full access
# to the original X11 display. As virtually no X11 client supports the untrusted
# mode correctly we set this to yes.
ForwardX11Trusted yes
# Send locale-related environment variables
SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
SendEnv XMODIFIERS
二、服务端配置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.
#############1. 关于 SSH Server 的整体设定##############
设置sshd监听的端口号,了安全起见,建议更改默认的22端口为5位以上陌生端口
#Port 22
#AddressFamily any
设置sshd服务器绑定的IP地址,默认所有ip
#ListenAddress 0.0.0.0
#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
ssh1和ssh2,ssh1是不安全的
Protocol 2
#############2. 说明主机的 Private Key 放置的档案##########
# HostKey for protocol version 1
设置ssh1密匙文件位置
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
设置ssh2密钥文件位置
#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
设置在记录来自sshd的消息的时候,是否给出“facility code”
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
设置记录sshd日志消息的层次。INFO是一个好的选择。查看sshd的man帮助页,获取更多的信息
#LogLevel INFO
#################3.安全认证方面的设定################
#############3.1、有关安全登录的设定###############
限制用户必须在指定的时限内认证成功,0 表示无限制。默认值是 120 秒
# Authentication:
设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位)
#LoginGraceTime 2m
设置是否允许root通过ssh登录。这个选项从安全角度来讲应设成"no"
#PermitRootLogin yes
设置ssh在接收登录请求之前是否检查用户家目录和rhosts文件的权限和所有权。这通常是必要的,因为新手经常会把自己的目录和文件设成任何人都有写权限
#StrictModes yes
设置客户端登录失败允许次数
#MaxAuthTries 6
设置允许客户端同时连接的个数
#MaxSessions 10
用来设置是否开启RSA密钥验证,只针对SSH1
#RSAAuthentication yes
用来设置是否开启公钥验证,如果使用公钥验证的方式登录时,则设置为yes
#PubkeyAuthentication yes
用来设置公钥验证文件的路径,与PubkeyAuthentication配合使用,默认值是".ssh/authorized_keys"
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody
#############3.2、安全验证的设定###############
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
设置是否允许用rhosts或“/etc/hosts.equiv”加上RSA进行安全验证
是否使用强可信主机认证(通过检查远程主机名和关联的用户名进行认证)。仅用于SSH-1。这是通过在RSA认证成功后再检查 ~/.rhosts 或 /etc/hosts.equiv 进行认证的。出于安全考虑,建议使用默认值"no"。
#RhostsRSAAuthentication no
# similar for protocol version 2
这个指令与 RhostsRSAAuthentication 类似,但是仅可以用于SSH-2。
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
设置ssh daemon是否在进行RhostsRSAAuthentication安全验证的时候忽略用户的"$HOME/.ssh/known_hosts”
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
设置验证的时候是否使用“rhosts”和“shosts”文件
#IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here!
设置是否允许口令验证
#PasswordAuthentication yes
设置是否允许用口令为空的帐号登录
#PermitEmptyPasswords no
PasswordAuthentication yes # Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
是否允许质疑-应答(challenge-response)认证
ChallengeResponseAuthentication no
########3.3、与 Kerberos 有关的参数设定,指定是否允许基于Kerberos的用户认证########
# Kerberos options
是否要求用户为PasswdAuthentication提供的密码必须通过Kerberos KDC认证,要使用Kerberos认证,服务器必须提供一个可以校验KDC identity的Kerberos servtab。默认值为no
#KerberosAuthentication no
如果Kerberos密码认证失败,那么该密码还将要通过其他的的认证机制,如/etc/passwd
#KerberosOrLocalPasswd yes
设置是否在用户退出登录是自动销毁用户的ticket
#KerberosTicketCleanup yes
如果使用AFS并且该用户有一个Kerberos 5 TGT,那么开启该指令后,将会在访问用户的家目录前尝试获取一个AFS token,并尝试传送 AFS token 给 Server 端,默认为no
#KerberosGetAFSToken no
#KerberosUseKuserok yes
####3.4、与 GSSAPI 有关的参数设定,指定是否允许基于GSSAPI的用户认证,仅适用于SSH2####
GSSAPI 是一套类似 Kerberos 5 的通用网络安全系统接口。如果你拥有一套 GSSAPI库,就可以通过 tcp 连接直接建立 cvs 连接,由 GSSAPI 进行安全鉴别
# GSSAPI options
指定是否允许基于GSSAPI的用户认证,默认为no
#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'.
设置是否通过PAM验证
#UsePAM no
UsePAM yes
AcceptEnv 指定客户端发送的哪些环境变量将会被传递到会话环境中。[注意]只有SSH-2协议支持环境变量的传递。指令的值是空格分隔的变量名列表(其中可以使用'*'和'?'作为通配符)。
也可以使用多个 AcceptEnv 达到同样的目的。需要注意的是,有些环境变量可能会被用于绕过禁止用户使用的环境变量。由于这个原因,该指令应当小心使用。默认是不传递任何环境变量
# 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
设置是否允许允许tcp端口转发,保护其他的tcp连接
#AllowTcpForwarding yes
设置是否允许远程客户端使用本地主机的端口转发功能,出于安全考虑,建议禁止
#GatewayPorts no
#############3.5、X-Window下使用的相关设定###############
设置是否允许X11转发
#X11Forwarding no
X11Forwarding yes
指定X11 转发的第一个可用的显示区(display)数字。默认值是 10 。可以用于防止 sshd 占用了真实的 X11 服务器显示区,从而发生混淆
#X11DisplayOffset 10
#X11UseLocalhost yes
设置sshd是否在用户登录的时候显示“/etc/motd”中的信息 #################3.6、登入后的相关设定#################
用来设置sshd是否在用户登录时显示“/etc/motd”中的信息,可以选在在“/etc/motd”中加入警告的信息
#PrintMotd yes
是否显示上次登录信息
#PrintLastLog yes
是否持续连接,设置yes可以防止死连接,一般而言,如果设定这项的话,那么 SSH Server 会传送 KeepAlive 的讯息给 Client 端,以确保两者的联机正常!
这种消息可以检测到死连接、连接不当关闭、客户端崩溃等异常。在这个情况下,任何一端死掉后, SSH 可以立刻知道,而不会有僵尸程序的发生!
#TCPKeepAlive yes
设置是否在交互式会话的登录过程中使用。默认值是"no",如果开启此指令,那么X11Forwarding 将会被禁止,因为login不知道如何处理 xauth cookies 。
需要注意的是,在SSH底下本来就不接受 login 这个程序的登入,如果指UsePrivilegeSeparation ,那么它将在认证完成后被禁用
#UseLogin no
设置使用者的权限
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
通常情况下我们在连接 OpenSSH服务器的时候假如 UseDNS选项是打开的话,服务器会先根据客户端的 IP地址进行 DNS PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正向A记录查询,
并验证是否与原始 IP地址一致,通过此种措施来防止客户端欺骗。平时我们都是动态 IP不会有PTR记录,所以打开此选项也没有太多作用。我们可以通过关闭此功能来提高连接 OpenSSH 服务器的速度
UseDNS no
#PidFile /var/run/sshd.pid
设置同时允许几个尚未登入的联机,当用户连上ssh但并未输入密码即为所谓的联机,在这个联机中,为了保护主机,所以需要设置最大值,预设为10个,而已经建立联机的不计算入内,
所以一般5个即可,这个设置可以防止恶意对服务器进行连接
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
############3.7、开放禁止用户设定############
当只有AllowUsers选项时,是白名单机制,只有允许的用户可以登录;当同时存在AllowUsers和DenyUsers时,是黑名单机制,只要用户不在黑名单里,都是可以登录的;两个选项都没有时,任何用户都可以登录
#AllowUsers<用户名1> <用户名2> <用户名3> ...
##指定允许通过远程访问的用户,多个用户以空格隔开
#AllowGroups<组名1> <组名2> <组名3> ...
##指定允许通过远程访问的组,多个组以空格隔开。当多个用户需要通过ssh登录系统时,可将所有用户加入一个组中。
#DenyUsers<用户名1> <用户名2> <用户名3> ...
##指定禁止通过远程访问的用户,多个用户以空格隔开
#DenyGroups<组名1> <组名2> <组名3> ...
##指定禁止通过远程访问的组,多个组以空格隔开。
# no default banner path
设置登录时提示信息,首先编辑一个文件,如bannertest.txt,文件内容自行定义。然后打开/etc/ssh/sshd_config文件并查找下面这样的行:#Banner /some/path将#号去掉,然后将bannertest.txt文件的全路径替换/some/path,然后保存,重启ssh服务。当客户端登录时,就会看到bannertest.txt文件中的提示信息
#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
三、相关命令行
service ssh status
ssh: unrecognized service
# service sshd status
openssh-daemon (pid 13237) is running...
# /etc/init.d/sshd status
openssh-daemon (pid 13237) is running...
# /etc/init.d/sshd -h
Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}
# service sshd -h
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
# service sshd st
Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}
那么要先生成两个密钥:
#ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
#ssh-keygen -t dsa -f /etc/ssh/ssh_host_rsa_key
执行命令后都会让输入密码,直接敲回车设置为空即可
参考:
1、http://blog.csdn.net/field_yang/article/details/51568861
ssh配置含义解释的更多相关文章
- mysql+ssh 配置(转载)
Mysql+ssh配置 一.Linux平台间mysql+ssh配置 本机地址为:192.168.189.133 mysql服务器地址为:192.168.189.139 linux命令行下使用ssh命令 ...
- struts.xml在Action配置具体解释
在博客上我已经基本上解释struts.xml基本配置.配置过程最为基本的是action的动态配置. 一.Action的创建方法 1)实现Action接口 2)继承ActionSupport类,覆写当中 ...
- linux SSH各配置项解释
Linux下SSH各配置项解释 关于ssh 设置的相关总结(ssh最大连接数.ssh连接时长.安全性配置等)以redhat6.3为例 ssh配置文件在: /etc/ssh/sshd_config可以打 ...
- [转]php-fpm配置具体解释
[转]php-fpm配置具体解释 php-fpm具体解释 原文链接:http://php-fpm.anight.org/wiki:http://www.php-fpm.com/翻译:http://sy ...
- linux中shell变量$#,$@,$0,$1,$2的含义解释
linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...
- Ngrok远程桌面及ssh配置
上一篇Ngrok 内网穿透利器 使用教程我们讲到Ngrok的基本使用教程,这篇描述一下Ngrok的远程桌面及ssh配置 Step 1 修改配置文件ngrok.cfg server_addr: &quo ...
- centos ssh配置使用
配置 数据阶梯 CentOS SSH配置 默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此.所以这里就不介绍OpenSSH的安装了. SSH配置: 1.修改vi /etc/ssh/ ...
- CentOS SSH配置
默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此.所以这里就不介绍OpenSSH的安装了. SSH配置: 1.修改vi /etc/ssh/sshd_config,根据模板将要修改的 ...
- linux中shell变量$#,$@,$0,$1,$2的含义解释
linux中shell变量$#,$@,$0,$1,$2的含义解释 linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID ...
随机推荐
- leetcode 【 Remove Element 】python 实现
题目: Given an array and a value, remove all instances of that value in place and return the new lengt ...
- Python 拓展之迭代器
写在之前 今天来讲讲「迭代器」的内容,其实已经拖了好多天了,感觉再不写就要忘记了.「迭代」相信对你来说已经不陌生了,我前面曾经专门用一篇文章来讲,如果你已经没有什么印象的话,就再点进去看看(零基础学习 ...
- sqlserver导入dbf文件
select top 10000 * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','dBase IV;HDR=NO;IMEX=2;DATABASE=E:/日常/ ...
- git 远程仓库回滚
git branch backup #创建备份分支 git push origin backup:backup #push到远程 git reset --hard commit_id #本地分支回滚 ...
- 【bzoj4259/bzoj4503】残缺的字符串/两个串 FFT
bzoj4259 题目描述 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有 ...
- 生成比较短的Token字符串
有的时候,我们需要生成一些Token作为标识:如认证后的标识符,资源的提取码等.一个比较常见的算法是生成一个GUID来作为Token,由于GUID的随机性和唯一性特点,作为Token是一个非常可靠的选 ...
- bzoj2553【beijing2011】禁忌
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=2553 sol :puts("nan"); (逃~ ac自动机+矩阵快速幂 ...
- Java EE 学习(6):IDEA + maven + spring 搭建 web(2)- 配置 Spring
参考:https://my.oschina.net/gaussik/blog/513353 注:此文承接上一文:Java EE 学习(5):IDEA + maven + spring 搭建 web(1 ...
- 勒索病毒 -- “永恒之蓝”NSA 武器免疫工具
“永恒之蓝”NSA 武器免疫工具 针对 445 端口:445端口是一个毁誉参半的端口,他和139端口一起是IPC$入侵的主要通道.有了它我们可以在局域网中轻松访问各种共享文件夹或共享打印机,但也正是因 ...
- react-router路由参数
react-router会自动为路由组件插入三个参数,但是不会主动为路由组件的子组件注入 子组件当中需要在属性当中传入 不是路由组件需要注入路由参数的话,也可以使用withRouter注入,而不是从属 ...