一、OpenSSH
OpenSSH與SSH協議是遠程登錄的首選連接工具。它加密所有流量,以消除竊聽,連接劫持和其它攻擊。OpenSSH常常被誤認以為與OpenSSL有關系,但實際上這兩個項目的有不同的目的,不同的發展團隊,名稱相近只是因為兩者有同樣的軟件發展目標──提供開放源代碼的加密通訊軟件。
OpenSSH的套件包括以下工具:
-
遠程操作使用 SSH, SCP,和 SFTP。
-
密鑰管理 ssh-add, ssh-keysign, ssh-keyscan和ssh-keygen
-
服務端組成 sshd, SFTP服務器和 ssh-agent的。
OpenSSH的功能:
-
具有完全的開源項目
OpenSSH的源代碼是免費提供給通過互聯網大家。這鼓勵代碼重用和代碼審核。代碼審查,以確保該漏洞可以被發現和被任何人糾正。這導致的安全密碼。OpenSSH的不受任何限制的許可證。它可以用于任何和所有目的,并且明確包括商業用途。 該許可證包括在分布。我們覺得這個世界會更好,如果路由器,網絡設備,操作系統,和所有其他的網絡設備已經SSH集成到他們。限制性性質(即專利)的所有成分被從源代碼移除。任何許可或專利的組件從外部庫(如選擇 LibreSSL)。
-
強大的加密(AES,ChaCha20,RSA,ECDSA,Ed25519 …)
加密身份驗證之前啟動,沒有密碼或其他信息以明文傳輸。加密也可用于防止欺騙的包。許多不同的密碼和密鑰類型可供選擇,和傳統的選項通常在合理時間內逐步淘汰。
-
X11轉發(也加密X窗口系統的流量)
X11轉發允許遠程X窗口的流量進行加密,使沒有人可以窺探您的遠程xterm終端或插入惡意命令。該程序會自動設置服務器計算機上顯示,并轉發了安全通道的X11連接。假XAUTHORITY信息自動生成并轉發到遠程機器; 本地客戶端會自動檢查傳入X11連接,并取代與真實數據(從不告訴遠程計算機中的真實信息)假授權數據。
-
端口轉發(對于傳統協議加密頻道)
端口轉發允許通過加密通道TCP / IP連接到遠程計算機上的轉發。像POP不安全的互聯網應用程序可以用此來保護。
-
強大的身份驗證(公共密鑰,一次性密碼)
強大的身份驗證可以防止一些安全問題:IP欺騙,偽造路線和DNS欺騙。一些身份驗證方法包括公共密鑰認證,具有S /鍵一次性密碼和驗證使用Kerberos(僅適用于 – 便攜式)。
-
代理轉發
一個認證代理,在用戶的筆記本電腦或本地工作站上運行,可用于容納用戶的認證密鑰。OpenSSH的自動轉發過任何連接到驗證代理的連接,并且也沒有必要存儲該網絡(除了用戶自己的本地機)中的任何計算機上的認證密鑰。該認證協議絕不泄露密鑰; 它們只能用于驗證用戶的代理具有一定的鍵。最終,該代理可依靠在智能卡上執行所有驗證計算。
-
互通性
實施之間的互操作性是一個目標,但不是一個承諾。由于OpenSSH的開發的進展,對已知舊協議的弱點,加密算法,密鑰類型和其他選項例行禁用。
-
SFTP客戶端和服務器支持在這兩個SSH1及SSH2協議
由于OpenSSH的2.5.0,完全支持SFTP包括,使用 SFTP 命令作為客戶端。在 SFTP服務器 子系統自動工作在兩個SSH1及SSH2協議。
-
可選的數據壓縮
加密之前數據壓縮提高低速網絡鏈路的性能。
1、ssh客戶端
ssh:Secure Shell創建在應用層和傳輸層基礎上的安全協議
配置文件為:/etc/ssh/ssh_config
[root@localhost ssh]# vim /etc/ssh/ssh_config # $OpenBSD: ssh_config,v 1.28 2013/09/16 11:35:43 sthen 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 #“ForwardAgent”設置連接是否經過驗證代理(如果存在)轉發給遠程計算機。 ForwardX11 no #“ForwardX11”設置X11連接是否被自動重定向到安全的通道和顯示集(DISPLAY set)。 RhostsAuthentication no #“RhostsAuthentication”設置是否使用基于rhosts的安全驗證。 RhostsRSAAuthentication no #“RhostsRSAAuthentication”設置是否使用用RSA算法的基于rhosts的安全驗證。 RSAAuthentication yes #“RSAAuthentication”設置是否使用RSA算法進行安全驗證。 PasswordAuthentication yes #“PasswordAuthentication”設置是否使用口令驗證。 FallBackToRsh no #“FallBackToRsh”設置如果用ssh連接出現錯誤是否自動使用rsh。 UseRsh no #“UseRsh”設置是否在這臺計算機上使用“rlogin/rsh”。 BatchMode no #“BatchMode”如果設為“yes”,passphrase/password(交互式輸入口令)的提示將被禁止。當不能交互式輸入口令的時候,這個選項對腳本文件和批處理任務十分有用。 CheckHostIP yes #“CheckHostIP”設置ssh是否查看連接到服務器的主機的IP地址以防止DNS欺騙。建議設置為“yes”。 StrictHostKeyChecking no #“StrictHostKeyChecking”如果設置成“yes”,ssh就不會自動把計算機的密匙加入“$HOME/.ssh/known_hosts”文件,并且一旦計算機的密匙發生了變化,就拒絕連接。 IdentityFile ~/.ssh/identity #“IdentityFile”設置從哪個文件讀取用戶的RSA安全驗證標識。 Port 22 #“Port”設置連接到遠程主機的端口。 Cipher blowfish #“Cipher”設置加密用的密碼。 EscapeChar ~ #“EscapeChar”設置escape字符。
在這個配置文件中,我們一般只修port的端口,因為默認端口很容易受到攻擊,ssh的默認端口為22號端口
如果我要登錄某ssh服務器則直接使用ssh username@host然后按照提示輸入密碼即可
[root@localhost ssh]# ssh root@172.16.11.55 [root@localhost ssh]# ssh root@172.16.11.55 root@172.16.11.55's password: Last login: Thu Apr 14 02:04:55 2016 from 172.16.7.211
ssh密鑰認證登錄
#生成密鑰對 [root@localhost ~]# ssh-keygen -t rsa Generating public/private rsa key pair. #這里詢問你要把生成的密鑰文件保存在哪里,默認是在家目錄下的.ssh文件夾中,回車保存默認目錄 Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. #這里是對密鑰文件加密,不輸入則表示不加密 Enter passphrase (empty for no passphrase): Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 04:9f:cb:9c:9d:1e:47:d7:e1:d4:c1:87:71:c3:a4:22 root@localhost.localdomain The key's randomart image is: +--[ RSA 2048]----+ | . =O+| | o . ===| | +E .....o| | + +.o.. | | S + . | | . o | | . | | | | | +-----------------+ #已經成功生成了一對密鑰 [root@localhost ~]# ls /root/.ssh id_rsa id_rsa.pub #其中id_rsa為私鑰,id_rsa.pub為公鑰 #在生成完密鑰對之后將公鑰上傳給服務器對應用戶的家目錄 [root@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub root@172.16.9.9 The authenticity of host '172.16.9.9 (172.16.9.9)' can't be established. ECDSA key fingerprint is 63:b9:6d:20:f0:22:b2:21:44:26:91:03:97:21:ff:b7. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@172.16.9.9's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@172.16.9.9'" and check to make sure that only the key(s) you wanted were added. #第一次輸入密碼后回車就上傳成功了 然后嘗試登錄 [root@localhost ~]# ssh 172.16.9.9 Last login: Tue Mar 22 10:01:02 2016 from 172.16.7.211 [root@localhost ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:83:15:cb brd ff:ff:ff:ff:ff:ff inet 172.16.9.9/16 brd 172.16.255.255 scope global eno16777728 valid_lft forever preferred_lft forever #可以看出不需要密鑰就成功登錄到了172.16.9.9這臺服務器上了
在windows中使用密鑰登錄對應的服務器
這里我使用Xshlle
這里的密碼是對密鑰加密的,不加密直接點下一步
這里顯示的就是公鑰,點保存為文件,也可以直接復制
之后關閉
然后登錄對應服務器,進入家目錄下的.ssh/文件
[root@localhost ~]# cd /root/.ssh/ [root@localhost .ssh]# ls authorized_keys known_hosts
編輯authorized_keys文件
[root@localhost .ssh]# vim authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoYslgClb39L0aPM8II18VBMG/pBHOR5kMKBAq6+9MQFCvOsIqS0tNEFPkbCQaIkKyZahRpdOP4FSgWOmX18uuLqG1MZT/FoAKGV4tJzKwcGpMjfTJVxhMVW+mUi4sxzF2atl8q0SmvzqnJHD5Sg6T2mlV0TC+xdbB5Q/ucFZAiflLkVfSEMBjzvJZTHe8QCLFS358xHKOzv4jfnaZVnsIpZ/LArzy/Y/hvPoamWSg794XlqEuascwPGkLq6VYbltT24gEy89/lAJfK4vXRrZjVmCvfkU98X8oe5wQRxNrPDWPsWO0tBYCt2/LTx+1na5WOYPIxeo3tAZ5LYbRD5Kn root@localhost.localdomain #這是之前的公鑰,可以將剛才的公鑰復制粘貼在這之后 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr44c56Hx0dGCj1RTm7JoQkJn1P77y89IHG1S34onqmq/M0RpFn/rzjmxPgXiGS4FUr7LuPl0wLzczm29tTDGv8vkaeLcUeT9yz5pPh1NFNJKyBGNZ+6XQzx8dRw5Ez6bGOSN68kJ4uhZWyCVJl2KintCUWm9D/9ldvV0n8AvmfKsqZvPLEkxxE4zyxUy247AC7wtgd51pl0eRU+MqZ4JHZJ6xhJYgiYtxPR++D+VSeaGnlO7ihv19B3edEmltEs09BOd/Tgl9OuXy+q+fCz5WQekGO0ZkX6y6sSOd7qG11mR188Eccf/dlfymDeF+duKFvgLYATUu5ISCrulQEXfVw==
保存之后就可以在本地面密碼登錄了,只需要在登錄時選擇對應的密鑰即可
直接點確定
生成的密鑰文件也可以帶走,在不同的主機上使用
scp:遠程復制命令
常用選項:
-r: 遞歸復制;
-p: 保持原文件的屬性信息;
-q: 靜默模式
-P PORT: 指明remote host的監聽的端口;
下載:scp 遠程主機上的賬戶@遠程主機:遠程主機對應的文件 本機目錄
[root@localhost ~]# scp -r root@172.16.9.9:/root/tmp /root
上傳:scp 本機文件 遠程主機上的賬戶@遠程主機:遠程主機對應的目錄
[root@localhost ~]# scp -r /root root@172.16.9.9:/root/tmp
sftp:遠程文件管理
sftp可進行遠程的文件的下載,目錄的刪除和建立等
sftp [user@]host
使用help查看可用命令
[root@localhost tmp]# sftp root@172.16.9.9 root@172.16.9.9's password: Connected to 172.16.9.9. sftp> help Available commands: bye Quit sftp#退出 cd path Change remote directory to 'path'#復制 chgrp grp path Change group of file 'path' to 'grp'#改變屬組 chmod mode path Change permissions of file 'path' to 'mode'#改變權限 chown own path Change owner of file 'path' to 'own'#改變屬主 df [-hi] [path] Display statistics for current directory or#查看磁盤使用量 filesystem containing 'path' exit Quit sftp#退出 get [-Ppr] remote [local] Download file#下載文件 reget remote [local] Resume download file help Display this help text lcd path Change local directory to 'path' lls [ls-options [path]] Display local directory listing#查看本地目錄下的文件 lmkdir path Create local directory#創建本地目錄 ln [-s] oldpath newpath Link remote file (-s for symlink) lpwd Print local working directory查看本地目錄路徑 ls [-1afhlnrSt] [path] Display remote directory listing查看遠端目錄文件 lumask umask Set local umask to 'umask' mkdir path Create remote directory創建遠端目錄 progress Toggle display of progress meter put [-Ppr] local [remote] Upload file pwd Display remote working directory查看遠端目錄路徑 quit Quit sftp退出 rename oldpath newpath Rename remote file rm path Delete remote file刪除遠端文件 rmdir path Remove remote directory刪除遠端目錄 symlink oldpath newpath Symlink remote file version Show SFTP version !command Execute 'command' in local shell ! Escape to local shell ? Synonym for help
2、服務器端
服務器端的配置文件為/etc/ssh/sshd_config,注意和客戶端對比多了一個d
配置文件中以#開頭后面帶空格的是注釋,不帶空格的是可選項
[root@localhost ~]# vim /etc/ssh/sshd_config # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 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:/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 override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # Port 22 #這里默認端口是22,可以改成其他端口,在作為服務器使用事建議改為其他端口,不要監聽默認端口,不要監聽默認端口,不要監聽默認端口 #AddressFamily any ListenAddress 0.0.0.0 #這里0.0.0.0代表監聽在本機的所有地址上 #ListenAddress :: # The default requires explicit activation of protocol 1 #Protocol 2 # HostKey for protocol version 1 #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2 #這里是主機密鑰的位置 HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Ciphers and keying #RekeyLimit default none # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH #這是主機日志的記錄方式。主機登錄日志的位置在 /var/log/secure SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin yes #這里表示是否允許管理員登錄,改成no之后就只能允許普通用戶登錄 #StrictModes yes #MaxAuthTries 6 #這是最大認證嘗試次數,默認為6次 #MaxSessions 10 #這是最大會話數,默認10個 #RSAAuthentication yes #PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #這是公鑰默認的保存位置 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #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 ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options GSSAPIAuthentication yes GSSAPICleanupCredentials no #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users 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'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no UsePrivilegeSeparation sandbox # Default for new installations. #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS no #這里表示是否反解DNS,建議改為no #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # 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 # override default of no subsystems #支持sftp遠程連接 Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
改完端口記得重啟sshd服務
二、創建私有CA并簽證給httpd服務器
CA:證書辦法機構
私有CA的ip地址:192.168.1.13
請求證書的主機,這里我使用的是一臺httpd主機:192.168.1.107
打開CA的openssl配置文件:/etc/pki/tls/openssl.cnf并查看和CA相關的配置
[root@localhost tls]# vim /etc/pki/tls/openssl.cnf #################################################################### [ CA_default ] dir = /etc/pki/CA # Where everything is kept#CA的工作目錄 certs = $dir/certs # Where the issued certs are kept#已簽發證書位置也就是/etc/pki/CA/certs crl_dir = $dir/crl # Where the issued crl are kept#證書吊銷列表的位置/etc/pki/CA/crl 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 ######################################################################## default_days = 365 # how long to certify for#證書有效期 default_crl_days= 30 # how long before next CRL#吊銷列表有效期
1、CA【192.168.1.13】創建需要的文件
[root@localhost ~]# cd /etc/pki/CA/ #創建index.txt文件 [root@localhost CA]# touch index.txt #創建序列號文件,這里用的01作第一個序列號 [root@localhost CA]# echo 01 > serial
2、給私有CA自簽證書
#生成密鑰對保存在/etc/pki/CA/private/cakey.pem中 [root@localhost CA]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048) Generating RSA private key, 2048 bit long modulus ..............................................+++ ...........................................................+++ e is 65537 (0x10001) [root@localhost CA]# ll private/ 總用量 4 -rw------- 1 root root 1675 3月 22 14:20 cakey.pem #自簽證書 [root@localhost CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem Country Name (2 letter code) [XX]:cn #國家縮寫,只有2位 State or Province Name (full name) []:chongqing #地區名稱,全稱 Locality Name (eg, city) [Default City]:chongqing #城市名稱 Organization Name (eg, company) [Default Company Ltd]:xinfeng #組織名稱或公司名稱 Organizational Unit Name (eg, section) []:xxoo #部門名稱 Common Name (eg, your name or your server's hostname) []:ca.xinfeng.com #主機名,這里是CA主機通過DNS解析出來的名稱,請不要填錯 Email Address []:caadmin@xinfeng.com #郵箱地址
openssl req命令中各選項的含義:
-new:生成新證書簽署請求;
-x509:專用于CA生成自簽證書;
-key:生成請求時用到的私鑰文件;
-days:證書的有效期限;
-out:證書的保存路徑;
3、發證
請求證書的主機【192.168.1.107】生成請求
[root@localhost httpd]# mkdir /etc/httpd/ssl [root@localhost httpd]# cd /etc/httpd/ssl/ #給httpd服務器生產私鑰文件 [root@localhost ssl]# (umask 077;openssl genrsa -out httpd.key 2048) Generating RSA private key, 2048 bit long modulus ....................+++ ...+++ e is 65537 (0x10001) #用私鑰中提取的公鑰生成證書簽署請求,其中的信息要與自簽的CA保持一致 [root@localhost ssl]# openssl req -new -key httpd.key -days 365 -out /etc/httpd/ssl/httpd.csr Country Name (2 letter code) [XX]:cn State or Province Name (full name) []:chongqing Locality Name (eg, city) [Default City]:chongqing Organization Name (eg, company) [Default Company Ltd]:xinfeng Organizational Unit Name (eg, section) []:xxoo Common Name (eg, your name or your server's hostname) []:www.xinfeng.com#這里一定得是你httpd服務器的主機名 Email Address []:caadmin@xinfeng.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: #加密證書簽署請求 An optional company name []: [root@localhost ssl]# scp httpd.csr root@192.168.1.13:/root #將證書請求上傳到CA的/root目錄下
4、CA對證書請求進行簽證【192.168.1.13】
#對剛才上傳的/root/htppd.csr進行簽證,有效期356天,生成的證書是/root/httpd.crt [root@localhost ~]# openssl ca -in /root/httpd.csr -out /root/httpd.crt -days 365 Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Mar 22 06:58:31 2016 GMT Not After : Mar 22 06:58:31 2017 GMT Subject: countryName = cn stateOrProvinceName = chongqing organizationName = xinfeng organizationalUnitName = xxoo commonName = www.xinfeng.com emailAddress = caadmin@xinfeng.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 42:07:4F:68:C6:05:0D:40:C8:A0:32:BE:53:DC:01:DA:DC:E6:81:9D X509v3 Authority Key Identifier: keyid:D1:91:5E:B5:A4:06:9B:DF:4B:0A:54:6B:A9:15:35:36:56:A5:F9:38 Certificate is to be certified until Mar 22 06:58:31 2017 GMT (365 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated #可以在/etc/pki/CA/index.txt看到剛才簽署的01號證書 [root@localhost ~]# cat /etc/pki/CA/index.txt V 170322065831Z 01 unknown /C=cn/ST=chongqing/O=xinfeng/OU=xxoo/CN= # 將證書保存一份在/etc/pki/CA/certs/這個證書存取庫中 [root@localhost ~]# cp /root/httpd.crt /etc/pki/CA/certs/ #發回請求證書的主機下的的/etc/httpd/ssl/目錄下 [root@localhost ~]# scp /root/httpd.crt root@192.168.1.107:/etc/httpd/ssl/
5、httpd【192.168.1.107】打開https
#先安裝ssl模塊 [root@localhost ssl]#yum -y install mod_ssl [root@localhost ssl]# rpm -ql mod_ssl /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.modules.d/00-ssl.conf /usr/lib64/httpd/modules/mod_ssl.so /usr/libexec/httpd-ssl-pass-dialog /var/cache/httpd/ssl #打開/etc/httpd/conf.d/ssl.conf進行配置 [root@localhost ssl]# vim /etc/httpd/conf.d/ssl.conf ServerName www.xinfeng.com DocumentRoot "/var/www/html" SSLCertificateFile /etc/httpd/ssl SSLCertificateKeyFile /etc/httpd/ssl/httpd.key #將<VirtualHost _default_:443>改為 <VirtualHost *:443> #編輯httpd主配置文件 [root@localhost conf]# vim /etc/httpd/conf/httpd.conf ServerName www.xinfeng.com DocumentRoot "/var/www/html" Loadmodule ssl_module modules/mod_ssl.so
6、啟動https
[root@localhost conf.d]# systemctl start httpd [root@localhost conf.d]# ss -tunl Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN 0 0 *:20644 *:* udp UNCONN 0 0 *:68 *:* udp UNCONN 0 0 :::50143 :::* tcp LISTEN 0 128 *:22 *:* tcp LISTEN 0 100 127.0.0.1:25 *:* tcp LISTEN 0 128 :::80 :::* tcp LISTEN 0 128 :::22 :::* tcp LISTEN 0 100 ::1:25 :::* tcp LISTEN 0 128 :::443 :::*
可以看到80和443端口都啟動了
7、訪問測試
因為我這里的ip對應的網站都是我假設的,所以要通過網址訪問Ip需要修改host文件
在host文件中加入
192.168.1.107 www.xinfeng.com
將剛才的證書下載到本地
然后導入
可以看到其實已經成功了,但是因為我們自建的私有CA不是公認的證書辦法機構,所以不受信任
原創文章,作者:N17_信風,如若轉載,請注明出處:http://www.www58058.com/15072
寫的很詳細,學習了!