OpenSSH: ssh:secure shell 安全的shell 是一种协议(规范) OpenSSH:ssh协议的开原协议 dropbear:另一种开源协议 telnet : 23/tcp 没有任何加密功能。只能非管理员登录,但是可以su到管理员。 应用层协议的通信 跟底层是什么没有关系,与系统没关系 ssh---v2 方式1:三次握手后,发送服务器主机公钥 给客户端,认证一下远程主机。用户名密码登录 方式2:基于秘钥的认证,客户端,将 自己的公钥放在 服务器端的关于ssh秘钥的目录下,只需要用户名就可以登录 v1: 基于CRC-32做MAC ,不安全:中间人man- in - middle v2:双方主机协议选择安全的MAC方式,基于DH 算法做秘钥交换,基于RSA 或DSA算法实现身份认证 OpenSSH: C/S: c: ssh, scp, sftp windows作为客户端:shell,putty, securecrt s:sshd 客户端组件 ssh,配置文件: /etc/ssh/ssh_config 格式: ssh [user@]host [COMMAND] # 以当前用户登录[在远程主机上执行命令后又退回当前主机] ssh -l user host [command] # 指定用户名 -p port:远程服务器监听的端口。 -X :linux上实现图形化的协议 X11 forwarding , X11转发 配置文件下: HOST PATTERN PARAMETER VALUE 基于秘钥认证登录:linux-linux 1、在客户端生成秘钥对 ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa' 2、将公钥传输到远程主机上 ssh-copy-id id_rsa.pub root@192.168.112.110 3、可以直接ssh user@host 登录 windows - linux -rw-------. 1 root root 392 Oct 11 05:03 authorized_keys 注意权限 scp命令: 远程复制 scp [options] SRC... DEST/ 两种情形: pull: scp [options] [user@]host:/Path/somefile /Path/somewhere push:scp [options] /path/somefile [user@]host:/Path/somewhere 常用选项: -r :递归 -p:保持源文件的属性信息 -q:静默模式 -P port:指明远程主机监听的端口 sftp命令:依赖远程主机开启ssh服务 sftp [user@]host sftp> help 服务器端: sshd, 配置文件: /etc/ssh/sshd_config rqm -q openssh 配置文件: port ListenAddress 登录日志: /var/log/seecure PermitRootLogin no 禁止root登录 MaxSessions 10:最多会话数 Kerberos options:通过第三方统一认证,规模比较大的时候 X11Forwarding yes: Subsystem sftp /usr/libexec/openssh/sftp-server :支持sftp远程连接 UseDNS no :避免登录服务器,反向解析dns 限制可登陆用户的办法:把用户名或用户组写上去即可 AllowUsers: AllowGroups: ssh服务的最佳实践: 1、不要使用默认端口 2、禁止使用 v1 版本 3、限制可登陆用户 4、设定空闲会话超时时长 5、利用防火墙设置ssh访问策略 6、仅监听特定的IP地址,通常是内网ip 7、基于口令认证,使用强密码策略 tr -dc A-Za-z0-9 < /dev/uranfom | head -c 30 | xargs ---FF5ZnFd6QW34bznltxgMLuRJmtIHg9 8、基于秘钥的认证 9、禁止使用空密码 10、禁止root用户直接登录 11、限制ssh的访问频度,并发在线数 12、做好日志,最好不要本机保存 日志,日志服务器。经常做分析。 ssh的另一种实现:dropbear OpenSSL: 三个组件: openssl:多用途的命令行工具 libcrypto:加密解密库 libssl: 是ssl协议的实现 PKI:公钥基础设施 CA:发证 RA:注册机构 CRL:吊销结构 证书的存储库 VPN: 建立私有CA:在一个组织内被信任 工具: OpenCA:比较专业,是OpenSSL的二次封装 OpenSSL: 证书申请及签署步骤: 1、生成申请请求 2、RA核验 3、CA签署 4、获取证书 创建私有CA: 1、创建所需要的文件 touch index.txt echo 01 > serial ls -al drwxr-xr-x. 2 root root 4096 Mar 23 2017 certs drwxr-xr-x. 2 root root 4096 Mar 23 2017 crl -rw-r--r--. 1 root root 0 Oct 13 03:58 index.txt drwxr-xr-x. 2 root root 4096 Mar 23 2017 newcerts drwx------. 2 root root 4096 Mar 23 2017 private -rw-r--r--. 1 root root 3 Oct 13 03:59 serial 2、CA自签证书 私钥:(umask 077; openssl genrsa -out private/cakey.pem 2048) 自签整数会自动提取公钥 生成自签证书: [root@localhost private]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem -new : 生成新证书签署请求 -x509:专用于CA生成自签证书 -key:生成请求时用到的私钥文件 -days:证书的有效期 -out: 证书的保存路径 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:Beijing Locality Name (eg, city) [Default City]:Beijing Organization Name (eg, company) [Default Company Ltd]:MageEdu Organizational Unit Name (eg, section) []:Ops Common Name (eg, your name or your server's hostname) []:ca.magedu.com # 这块尤其重要,要跟自己CA服务器dns解析出来的名字一样 Email Address []:caadmin@magedu.com 3、发证: a、用到证书的主机生成证书请求 比如 httpd为例 在 /etc/httpd/ 下创建ssl目录 在ssl下生成秘钥 (umask 077; openssl genrsa -out httpd.key 2048) 生成请求: openssl req -new -key httpd.key -days 365 -out httpd.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:Beijing Locality Name (eg, city) [Default City]:Beijing Organization Name (eg, company) [Default Company Ltd]:MageEdu Organizational Unit Name (eg, section) []:Ops Common Name (eg, your name or your server's hostname) []:www.magedu.com # 要注意这个,作为web服务器,别人是通过www访问,所以注意 Email Address []:webadmin@mage.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: b、把请求文件传输给CA scp传过去 C、CA签署证书,并将证书传输给请求者 证书的后缀 crt 签署证书: openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 365 再scp传给请求者 查看证书中的信息: openssl x509 -in CERT_FILE -noout -text| -subject|-serial 4、吊销证书: a、客户端获取要吊销的证书的serial # 在请求端执行 openssl x509 -in cert_file -noout -serial -subjct b、CA:先根据客户端提交的serial与subject对比检验是否与index.txt文件中的信息一致 吊销:openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem c、生成吊销证书的编号:让别人知道 作为CA第一次吊销某证书: echo 01 > /etc/pki/CA/crlnumber d、更新证书吊销列表 openssl ca -gencrl -out thisca.crl 查看crl文件 openssl crl -in /crl_file.crl -noout -text 配置文件 /etc/pki/tls/openssl.cnf 工作目录:/etc/pki/CA [ CA_default ] dir = /etc/pki/CA # Where everything is kept certs = $dir/certs # Where the issued certs are kept crl_dir = $dir/crl # Where the issued crl are kept database = $dir/index.txt # database index file. #unique_subject = no # Set to 'no' to allow creation of # several ctificates with same subject. new_certs_dir = $dir/newcerts # default place for new certs. # 刚刚签的证书 certificate = $dir/cacert.pem # The CA certificate # CA自己的证书 serial = $dir/serial # The current serial number #吊销证书的序列号 crlnumber = $dir/crlnumber # the current crl number # must be commented out to leave a V1 CRL crl = $dir/crl.pem # The current CRL private_key = $dir/private/cakey.pem# The private key # CA自己的私钥路径 RANDFILE = $dir/private/.rand # private random number file x509_extensions = usr_cert # The extentions to add to the cert # Comment out the following two lines for the "traditional" # (and highly broken) format. name_opt = ca_default # Subject Name options cert_opt = ca_default # Certificate field options