Security configuration of SSH login entry - enterprise security practice

catalog

0. 引言
1. 修改ssh端口
2. 禁用root远程ssh登录
3. 只使用SSH v2
4. 限制用户的SSH访问
5. 禁用.rhosts文件
6. 禁用基于主机的身份验证
7. 基于公私钥的证书登录
8. Linux SSH配置基线检查

0. 引言

关于企业IT系统建设安全性问题在任何时候都不会成为一个过时的话题,企业在构建适合自己业务需求的IT系统之初以及整个IT系统生命周期内,系统的安全运行都是一项非常重要的工作,安全健康体检主要着眼于服务器的入口安全,SSH服务是目前类unix系统上使用最为广泛的远程安全登录服务之一,默认端口为tcp 22端口。由于远程管理的需要,很多防火墙都对外开放了22端口,这就使得SSH服务很容易成为黑客的攻击目标。为避免系统的SSH服务被黑客攻击,我们需要对SSH服务进行一些加固操作,以保证服务器的安全

Relevant Link:

http://xjsunjie.blog.51cto.com/999372/691330
http://security.zdnet.com.cn/security_zone/2009/1214/1556391.shtml
http://blog.chinaunix.net/uid-25723371-id-4542221.html
http://www.cyberciti.biz/faq/ssh-passwordless-login-with-keychain-for-scripts/
http://heyihome.blog.51cto.com/2657805/480885

1. 修改ssh端口

SSH的默认端口是tcp 22,从最佳实践的角度来说,将SSH入口端口修改为非默认值,有助于阻止黑客的恶意扫描攻击

1. vim /etc/ssh/sshd_config
2. 修改为port 11220
//ssh_config和sshd_config必须同时修改成11220,重启ssh服务(service sshd restart)后方可生效

2. 禁用root远程ssh登录

从最佳实践的角度来说,入口点的身份授权应该遵循"最小化权限原则",即用户应该在准确识别自己的业务需要,创建并赋予帐号最小化仅仅够用的权限,使用这个帐号进行登录

1. vim /etc/ssh/sshd_config
2. 修改PermitRootLogin no
3. 重启sshd服务: #servicesshd restart

没有必要使用root用户通过SSH远程登录,普通用户可以通过su或sudo(推荐)获得root级别的访问权,这样你可以得到完整的审计信息,谁通过sudo在系统上执行特权命令就会一清二楚

3. 只使用SSH v2

SSH协议的第一个版本(SSH v1或SSH-1)存在中间人攻击问题和安全漏洞,它已经被作废,应该避免使用SSH v1

1. vim /etc/ssh/sshd_config
2. 增加Protocol 2

这样启动sshd后就只会使用SSH协议的第二个版本(SSH v2或SSH-2)了

4. 限制用户的SSH访问

默认情况下,所有系统用户都可以用他们的密码或公钥通过SSH实现远程登录,但有时你创建的UNIX/Linux用户是用于ftp或email目的,如果不加限制,这些用户也可以使用ssh登录到系统

1. vim /etc/ssh/sshd_config
2. 增加AllowUsers root vivek jerry
//只允许root、vivek、jerry进行ssh登录

5. 禁用.rhosts文件

不要读取用户的~/.rhosts和~/.shosts文件,使用下面的设置更新sshd_config配置文件

1. vim /etc/ssh/sshd_config
2. IgnoreRhosts yes

SSH可以模拟过时的rsh命令的行为,rsh被公认为是不安全的远程访问协议,因此必须得禁用掉

Relevant Link:

https://www-uxsup.csx.cam.ac.uk/doc/remote_access/rhosts.html
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.qb.server.doc/doc/t0007952.html?lang=zh
http://www.mcsr.olemiss.edu/unixhelp/tasks/3.6.1.2.html
http://www.cnblogs.com/itech/archive/2012/09/09/2678097.html

6. 禁用基于主机的身份验证

禁用基于主机的身份验证,使用下面的选项更新sshd_config配置文件

1. vim /etc/ssh/sshd_config
2. HostbasedAuthentication no

7. 基于公私钥的证书登录 

0x1: 证书登录的步骤

1. 客户端生成证书:私钥和公钥,然后私钥放在客户端,妥当保存,一般为了安全,会设置一个密码,以后每次登录ssh服务器时,客户端都要输入密码解开私钥
ssh-keygen -t rsa
/*
rsa是一种密码算法,还有一种是dsa,证书登录常用的是rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /home/user/.ssh/id_rsa
(生成私钥与公钥存放位置,使用哪个账户操作就放在哪个账户下面)
Enter passphrase (empty for no passphrase): 输入密码
Enter same passphrase again:再次输入密码
Your identification has been saved in /home/user/.ssh/id_rsa. (生成的私钥)
Your public key has been saved in /home/user/.ssh/id_rsa.pub. (生成的公钥)
The key fingerprint is:
76:04:4d:44:25:37:0f:b1:a5:b7:6e:63:d4:97:22:6b
*/

2. 服务器添加信用公钥: 把客户端生成的公钥,上传到ssh服务器,添加到指定的文件中
将生成的公钥id_rsa.pub复制一份并重命名为authorized_keys放在服务器用户主文件夹的.ssh目录下
//假设客户端想通过私钥要登录其他ssh服务器,同理,可以把公钥上传到其他ssh服务器 

3. 重新启动ssh服务:/etc/init.d/ssh restart

4. 简化客户端putty、xshell配置
启动客户端连接软件,点击Advanced选项,选择User Keys,点击Import Key,在弹出的“打开”中找到刚刚复制到本地的id_rsa文件并打开。输入在制作这个私钥时设置的密码,输入完确定之后为该key命名,确定后设置此证书在本地发起连接时是否需要输入密码,如需要则设置,不需要就留空,最后点击Ok,本地证书就制作添加完成了

真实的工作中:员工生成好私钥和公钥(千万要记得设置私钥密码),然后把公钥发给运维人员,运维人员会登记你的公钥,为你开通一台或者多台服务器的权限,然后员工就可以通过一个私钥,登录他有权限的服务器做系统维护等工作,所以,员工是有责任保护他的私钥的
0x2: SSH配置加固

1. vim /etc/ssh/sshd_config
2. PermitEmptyPasswords no #不允许空密码用户login(仅仅是明文密码方式,非证书方式)
3. RSAAuthentication yes #启用RSA认证
4. PubkeyAuthentication yes #启用公钥认证
5. PasswordAuthentication no #禁止密码认证
//补充: 修改vi /etc/ssh/ssh_config 文件(全局配置文件)
1. RSAAuthentication yes # 允许RSA私钥方式认证
2. PasswordAuthentication no #禁止明文密码登陆 

Relevant Link:

http://www.edu.cn/jm_9957/20120508/t20120508_774165.shtml
http://www.jb51.net/LINUXjishu/72805.html
http://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646346.html

8. Linux SSH配置基线检查

所有基线检查项都来自/etc/ssh/sshd_config

1. port
    1) expectedvalue: 非22
    2) vul: 缺省(#)、或显式配置为22
    3) discription: 建议将ssh默认端口改为9999之后的非默认端口,防止黑客的恶意扫描

2. PermitRootLogin
    1) expectedvalue: no
    2) vul: 缺省(#)、或显式配置为yes
    3) discription: 没有必要使用root用户通过SSH远程登录,普通用户可以通过su或sudo(推荐)获得root级别的访问权

3. Protocol
    1) expectedvalue: 2
    2) vul: 显式配置为1
    3) discription: SSH协议的第一个版本(SSH v1或SSH-1)存在中间人攻击问题和安全漏洞,它已经被作废,应该避免使用SSH v1 

4. IgnoreRhosts
    1) expectedvalue: yes
    2) vul: 显式配置为no
    2) discription: SSH可以模拟过时的rsh命令的行为,rsh被公认为是不安全的远程访问协议,因此必须得禁用掉

5. HostbasedAuthentication
    1) expectedvalue: no
    2) vul: 显式配置为yes
    3) discription: 建议禁用基于主机的身份验证

Copyright (c) 2015 LittleHann All rights reserved

时间: 2024-08-03 23:08:04

Security configuration of SSH login entry - enterprise security practice的相关文章

Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Security文档的说明: ------------------ auto-config Automatically registers a login form, BASIC authentication, logout services. If set to "true", all of thes

REST Security with JWT using Java and Spring Security

Security Security is the enemy of convenience, and vice versa. This statement is true for any system, virtual or real, from the physical house entrance to web banking platforms. Engineers are constantly trying to find the right balance for the given

Fixing ssh login long delay

原文:http://injustfiveminutes.com/2013/03/13/fixing-ssh-login-long-delay/ For a long time I had a problem with ssh login on a Redhat 6 server – it was taking too long to connect to it, around 30 seconds. Normally it hasn’t been a big issue – after all,

Could not resolve placeholder &#39;spring.security.mapping.directory&#39; in string value &quot;${spring.security

1.错误描述 2015-09-20 22:30:25 [main] WARN org.springframework.context.support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanDefinitionStoreException: In

Spring security 3.x 普通login与ajax login笔记

原创文章,欢迎转载!转载时务必保留:作者:jmppok ;出处http://blog.csdn.net/jmppok/article/details/44832641 1.问题 在一个Web项目中一般会有两部分组成: 1)静态资源, 如html页面, js脚本,图片等等. 2)API接口. 在进行权限控制时,需要对这两部分进行统一管理. Spring框架本身提供了强大的Security机制,但是在使用过程中还是会出现以下问题: 当用户访问一个页面时,页面本身经常是既包含静态资源,又需要调用API

ssh login without password

1. ssh-keygen Shufengs-iMac:~ wangbo$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/wangbo/.ssh/id_rsa): [enter-return] Enter passphrase (empty for no passphrase): <span style="font-family: Arial, H

ssh login nova vm

$ sudo cat >> /usr/bin/nova-ssh  << END FIRST=$1 IDX=`expr index $1 "@"`if [[ $IDX  == "0" ]] ; then    echo "please input the user name"    exit 1fiUSER=${FIRST%@*} IP=${FIRST#*@}NINFO=`nova list | grep $IP | awk

【转载】SSH login without password 免密登陆

Your aim You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script. How to

Cross-Domain Security For Data Vault

Cross-domain security for data vault is described. At least one database is accessible from a plurality of network domains, each network domain having a domain security level. The at least one database includes at least one partitioned data table tha