如何配置openSSH

安全 数据安全
OpenSSH是SSH(Secure SHell)协议的免费开源实现。它用安全、加密的网络连接工具代替了 telnet、ftp、 rlogin、rsh 和 rcp 工具。openSSH的设置文件和主要文件存放在/etc/ssh/目录中。

与SSH有关的配置文件

OpenSSH是SSH(Secure SHell)协议的免费开源实现。它用安全、加密的网络连接工具代替了 telnet、ftp、 rlogin、rsh 和 rcp 工具。OpenSSH 支持 SSH 协议的版本 1.3、1.5、和 2。自从 OpenSSH 的版本 2.9 以来,默认的协议是版本 2,该协议默认使用 RSA 钥匙。

openSSH的设置文件和主要文件存放在/etc/ssh/目录中,主要包括如下文件:

/etc/ssh/sshd_config:sshd服务器的设置文件

/etc/ssh/ssh_config:ssh客户机的设置文件

/etc/ssh/ssh_host_key:SSH1用的RSA私钥

/etc/ssh/ssh_host_key.pub:SSH1用的RSA公钥

/etc/ssh/ssh_host_rsa_key:SSH2用的RSA私钥

/etc/ssh/ssh_host_rsa_key.pub:SSH2用的RSA公钥

/etc/ssh/ssh_host_dsa_key:SSH2用的DSA私钥

/etc/ssh/ssh_host_dsa_key.pub:SSH2用的DSA公钥

配置“/etc/ssh/ssh_config”文件

“/etc/ssh/ssh_config”文件是OpenSSH系统范围的配置文件,允许用户通过设置不同的选项来改变客户端程序的运行方式。这个文件的每一行包含“关键词-值”的匹配,其中“关键词”是忽略大小写的。下面列出最重要的关键词,用man命令查看帮助页(ssh(1))可以得到详细的列表。

配置须要编辑“ssh_config”文件(vi /etc/ssh/ssh_config),添加或改变下面的参数:

# Site-wide defaults for various options

Host *

ForwardAgent no

ForwardX11 no

RhostsAuthentication no

RhostsRSAAuthentication no

RSAAuthentication yes

PasswordAuthentication yes

FallBackToRsh no

UseRsh no

BatchMode no

CheckHostIP yes

StrictHostKeyChecking no

IdentityFile ~/.ssh/identity

Port 22

Cipher blowfish

EscapeChar ~

下面逐行说明上面的选项设置:

Host *:只对能够匹配后面字串的计算机有效。“*”表示所有的计算机。

ForwardAgent no:“ForwardAgent”设置连接是否经过验证代理(如果存在)转发给远程计算机。

ForwardX11 no:设置X11连接是否被自动重定向到安全的通道和显示集(DISPLAY set)。

RhostsAuthentication no:是否用基于rhosts的安全验证。

RhostsRSAAuthentication no:是否用RSA算法的基于rhosts的安全验证。

RSAAuthentication yes:是否用RSA算法进行安全验证。

PasswordAuthentication yes:是否用口令验证。

FallBackToRsh no:如果用ssh连接出现错误是否自动使用rsh。

UseRsh no:是否在这台计算机上使用“rlogin/rsh”。

BatchMode no:如果设为“yes”,passphrase/password(交互式输入口令)的提示将被禁止。当不能交互式输入口令的时候,这个选项对脚本文件和批处理任务十分有用。

CheckHostIP yes:设置ssh是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设置为“yes”。

StrictHostKeyChecking no:如果设置成“yes”,ssh就不会自动把计算机的密钥加入“$HOME/.ssh/known_hosts”文件,并且一旦计算机的密钥发生了变化,就拒绝连接。

IdentityFile ~/.ssh/identity:设置从哪个文件读取用户的RSA安全验证标识。

Port 22:设置连接到远程主机的端口。

Cipher blowfish:设置加密用的密码。

EscapeChar ~:设置escape字符。

假定用户在www.super.com上有一个名为“baby”的账号。而且要把“ssh-agent”和“ssh- add”结合起来使用并且使用数据压缩来加快传输速度。因为主机名太长了,想使用“super”作为“www.super.com”的简称。那么,配置文件可以如下编写:

Host *super

HostName www.super.com

User baby

ForwardAgent yes

Compression yes

# Be paranoid by default

Host *

ForwardAgent no

ForwardX11 no

FallBackToRsh no

当用户输入“ssh super”之后,SSH会自动地从配置文件中找到主机的全名,使用用户名登录并且用“ssh-agent”管理的密钥进行安全验证。

配置“/etc/ssh/sshd_config”文件

“/etc/ssh/sshd_config”是OpenSSH的配置文件,允许设置选项改变这个daemon的运行。这个文件的每一行包含“关键词-值”的匹配,其中“关键词”是忽略大小写的。下面列出来的是最重要的关键词,用man命令查看帮助页(sshd(8))可以得到详细的列表。

编辑“sshd_config”文件(vi /etc/ssh/sshd_config),加入或改变下面的参数:

# This is ssh server systemwide configuration file.

Port 22

ListenAddress 192.168.1.1

HostKey /etc/ssh/ssh_host_key

ServerKeyBits 1024

LoginGraceTime 600

KeyRegenerationInterval 3600

PermitRootLogin no

IgnoreRhosts yes

IgnoreUserKnownHosts yes

StrictModes yes

X11Forwarding no

PrintMotd yes

SyslogFacility AUTH

LogLevel INFO

RhostsAuthentication no

RhostsRSAAuthentication no

RSAAuthentication yes

PasswordAuthentication yes

PermitEmptyPasswords no

AllowUsers admin

下面逐行说明上面的选项设置:

Port 22:“Port”设置sshd监听的端口号。

ListenAddress 192.168.1.1:“ListenAddress”设置sshd服务器绑定的IP地址。

HostKey /etc/ssh/ssh_host_key:“HostKey”设置包含计算机私人密钥的文件。

ServerKeyBits 1024:“ServerKeyBits”定义服务器密钥的位数。

LoginGraceTime 600:“LoginGraceTime”设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位)。

KeyRegenerationInterval 3600:“KeyRegenerationInterval”设置在多少秒之后自动重新生成服务器的密钥(如果使用密钥)。重新生成密钥是为了防止用盗用的密钥解密被截获的信息。

PermitRootLogin no:“PermitRootLogin”设置root能不能用ssh登录。这个选项一定不要设成“yes”。

IgnoreRhosts yes:“IgnoreRhosts”设置验证的时候是否使用“rhosts”和“shosts”文件。

IgnoreUserKnownHosts yes:“IgnoreUserKnownHosts”设置ssh daemon是否在进行RhostsRSAAuthentication安全验证的时候忽略用户的“$HOME/.ssh/known_hosts”。

StrictModes yes:“StrictModes”设置ssh在接收登录请求之前是否检查用户的目录和rhosts文件的权限和所有权。这通常是必要的,因为新手经常会把自己的目录和文件设成任何人都有写权限。

X11Forwarding no:“X11Forwarding”设置是否允许X11转发。

PrintMotd yes:“PrintMotd”设置sshd是否在用户登录的时候显示“/etc/motd”中的信息。

SyslogFacility AUTH:“SyslogFacility”设置在记录来自sshd的消息的时候,是否给出“facility code”。

LogLevel INFO:“LogLevel”设置记录sshd日志消息的层次。INFO是一个好的选择。查看sshd的man帮助页,可以获取更多的信息。

RhostsAuthentication no:“RhostsAuthentication”设置只用rhosts或“/etc/hosts.equiv”进行安全验证是否已经足够了。

RhostsRSAAuthentication no:“RhostsRSA”设置是否允许用rhosts或“/etc/hosts.equiv”加上RSA进行安全验证。

RSAAuthentication yes:“RSAAuthentication”设置是否允许只有RSA安全验证。

PasswordAuthentication yes:“PasswordAuthentication”设置是否允许口令验证。

PermitEmptyPasswords no:“PermitEmptyPasswords”设置是否允许用口令为空的账号登录。

AllowUsers admin:“AllowUsers”的后面可以跟着任意的数量的用户名的匹配串(patterns)或user@host这样的匹配串,这些字符串用空格隔开。主机名可以是DNS名或IP地址。

责任编辑:蓝雨泪 来源: TechTarget中国
相关推荐

2015-12-30 10:49:31

2021-02-23 09:12:46

网络安全系统安全OpenSS

2010-04-27 14:11:05

2018-02-28 17:27:28

2019-08-02 10:20:39

OpenSSHWindows 10SFTP

2015-10-20 14:21:19

微软WindowsOpenSSH

2010-02-07 14:09:57

Ubuntu open

2010-01-13 14:45:25

CentOS配置

2021-01-28 09:34:08

解密密钥取证分析

2016-03-15 16:29:46

2011-02-24 13:15:59

2011-02-21 17:58:50

2010-11-16 10:57:06

OpenSSH开源技术

2017-10-10 12:40:13

SSHTCPOpenSSH

2015-07-24 17:33:46

2010-04-13 18:42:55

2019-08-28 09:28:07

SSHOpenSSH运维

2009-04-08 10:35:00

静态路由配置

2023-06-27 08:30:48

2010-05-26 10:10:53

openssh
点赞
收藏

51CTO技术栈公众号