Hero Image
openvpn部署之部署基於AD域認證

openvpn 部署之部署基於 AD 域認證 OpenVPN + PAM + SSSD + Active Directory https://computingforgeeks.com/install-and-configure-openvpn-server-on-rhel-centos-8/ https://www.redhat.com/en/blog/consistent-security-crypto-policies-red-hat-enterprise-linux-8 https://medium.com/jerrynotes/linux-authentication-windows-ad-without-join-domain-7963c3fd44c5 # 安裝openvpn yum install openvpn -y yum -y install openssl openssl-devel -y yum -y install lzo lzo-devel -y yum install -y libgcrypt libgpg-error libgcrypt-devel # 安裝openvpn認證插件 yum install openvpn-auth-ldap -y # 安裝easy-rsa # 由於openvpn2.3之後,在openvpn裏面剔除了easy-rsa文件,所以需要單獨安裝 yum install easy-rsa cp -rf /usr/share/easy-rsa/2.0 /etc/opevpn/ # 生成openvpn的key及證書 # 修改 `/opt/openvpn/etc/easy-rsa/2.0/vars` 參數 export KEY_COUNTRY="CN" # 國家 export KEY_PROVINCE="ZJ" # 省份 export KEY_CITY="NingBo" # 城市 export KEY_ORG="TEST-VPN" # 組織 exportKEY_EMAIL="81367070@qq.com" # 郵件 export KEY_OU="baidu" # 單位 source vars ./clean-all ./build-ca ./build-dh ./build-key-server server ./build-key client1 # 編輯openvpn服務端配置文件:`/etc/openvpn/server.conf` port 1194 proto udp dev tun ca keys/ca.crt cert keys/server.crt key keys/server.key # This file should be kept secret dh keys/dh2048.pem server 10.8.0.0 255.255.255.0 //客戶端分配的ip地址 push "route 192.168.1.0 255.255.255.0" //推送客戶端的路由 push "redirect-gateway" //修改客戶端的網關,使其直接走vpn流量 ifconfig-pool-persist ipp.txt keepalive 10 120 comp-lzo persist-key persist-tun status openvpn-status.log verb 3 plugin /usr/lib64/openvpn/plugin/lib/openvpn-auth-ldap.so "/etc/openvpn/auth/ldap.conf" client-cert-not-required username-as-common-name log /var/log/openvpn.log # 修改openvpn-ldap-auth的配置文件 `/etc/openvpn/auth/ldap.conf` # /etc/openvpn/auth/ldap.conf <LDAP> # LDAP server URL # 更改爲 AD 服務器的 IP URL ldap://172.16.76.238:389 # Bind DN (If your LDAP server doesn't support anonymous binds) # BindDN uid=Manager,ou=People,dc=example,dc=com # 更改爲域管理的 DN, 可以通過 ldapsearch 進行查詢 # -h 的 ip 替換爲服務器 ip,-D 換爲管理員的 dn,-b 爲基礎的查詢 dn,* 爲所有 # ldapsearch -LLL -x -h 172.16.76.238 -D "administrator@xx.com" -W -b "dc=xx,dc=com" "*" BindDN "cn=administrator,cn=Users,dc=xx,dc=com" # Bind Password # Password SecretPassword # 域管理員的密碼 Password passwd # Network timeout (in seconds) Timeout 15 # Enable Start TLS TLSEnable no # Follow LDAP Referrals (anonymously) FollowReferrals no # TLS CA Certificate File # TLSCACertFile /usr/local/etc/ssl/ca.pem # TLS CA Certificate Directory # TLSCACertDir /etc/ssl/certs # Client Certificate and key # If TLS client authentication is required # TLSCertFile /usr/local/etc/ssl/client-cert.pem # TLSKeyFile /usr/local/etc/ssl/client-key.pem # Cipher Suite # The defaults are usually fine here # TLSCipherSuite ALL:!ADH:@STRENGTH </LDAP> <Authorization> # Base DN # 查詢認證的基礎 dn BaseDN "dc=boqii-inc,dc=com" # User Search Filter # SearchFilter "(&(uid=%u)(accountStatus=active))" # 其中 sAMAccountName=%u 的意思是把 sAMAccountName 的字段取值爲用戶名, # 後面 "memberof=CN=myvpn,DC=xx,DC=com" 指向要認證的 vpn 用戶組, # 這樣任何用戶使用 vpn,只要加入這個組就好了 SearchFilter "(&(sAMAccountName=%u)(memberof=CN=myvpn,DC=boqii-inc,DC=com))" # Require Group Membership RequireGroup false # Add non-group members to a PF table (disabled) # PFTable ips_vpn_users <Group> # BaseDN "ou=Groups,dc=example,dc=com" # SearchFilter "(|(cn=developers)(cn=artists))" # MemberAttribute uniqueMember # Add group members to a PF table (disabled) # PFTable ips_vpn_eng BaseDN "ou=vpn,dc=boqii-inc,dc=com" SearchFilter "(cn=openvpn)" MemberAttribute "member" </Group> </Authorization> 拷貝/etc/openvpn/key目錄下的ca.crt證書,以備客戶端使用。

Hero Image
使用 Vagrant 自動調整 VirtualBox 磁碟大小

使用 Vagrant 自動調整 VirtualBox 磁碟大小 Increasing Disk Space of a Linux-based Vagrant Box on Provisioning Vagrant.configure(2) do |config| config.vm.box = "centos/7" config.disksize.size = '20GB' end $ sudo parted /dev/sda resizepart 2 100% $ sudo lvextend -l +100%FREE /dev/centos/root $ sudo xfs_growfs /dev/centos/root 自動化部分 Vagrant.configure(2) do |config| common = <<-SCRIPT sudo parted /dev/sda resizepart 2 100% sudo pvresize /dev/sda2 sudo lvextend -l +100%FREE /dev/centos/root sudo xfs_growfs /dev/centos/root SCRIPT config.vm.define "node01" do |node1| node1.vm.hostname = "node01" node1.vm.network "private_network", ip: "192.168.56.121" config.vm.provision :shell, :inline => common end end vagrant plugin install vagrant-disksize Vagrantfile # Fail if the vagrant-disksize plugin is not installed unless Vagrant.has_plugin?("vagrant-disksize") raise 'vagrant-disksize is not installed!' end Vagrant.configure("2") do |config| config.vm.provider "virtualbox" do |vb| vb.name = "DISKEXTEND" vb.memory = 2048 vb.cpus = 2 end config.vm.define :"DISKEXTEND" do |t| end config.vm.hostname = "DISKEXTEND" config.vm.box = "bento/ubuntu-18.04" # Increase the default disk size of the bento image (64GB) to 96GB config.disksize.size = "96GB" # Run a script on provisioning the box to format the file system config.vm.provision "shell", path: "disk-extend.sh" end 佈署腳本:disk-extend.sh #!/bin/bash echo "> Installing required tools for file system management" if [ -n "$(command -v yum)" ]; then echo ">> Detected yum-based Linux" sudo yum makecache sudo yum install -y util-linux sudo yum install -y lvm2 sudo yum install -y e2fsprogs fi if [ -n "$(command -v apt-get)" ]; then echo ">> Detected apt-based Linux" sudo apt-get update -y sudo apt-get install -y fdisk sudo apt-get install -y lvm2 sudo apt-get install -y e2fsprogs fi ROOT_DISK_DEVICE="/dev/sda" ROOT_DISK_DEVICE_PART="/dev/sda1" LV_PATH=`sudo lvdisplay -c | sed -n 1p | awk -F ":" '{print $1;}'` FS_PATH=`df / | sed -n 2p | awk '{print $1;}'` ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'` echo "The root file system (/) has a size of $ROOT_FS_SIZE" echo "> Increasing disk size of $ROOT_DISK_DEVICE to available maximum" sudo fdisk $ROOT_DISK_DEVICE <<EOF d n p 1 2048 no w EOF sudo pvresize $ROOT_DISK_DEVICE_PART sudo lvextend -l +100%FREE $LV_PATH sudo resize2fs -p $FS_PATH ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'` echo "The root file system (/) has a size of $ROOT_FS_SIZE" exit 0

Hero Image
Google 搜尋運算子:完整清單(44 個進階運算子)

Google Search Operators: The Complete List (44 Advanced Operators) 可用 搜尋運算子 用途 範例 " " 搜尋包含特定字詞或片語的結果。 "steve jobs" OR 搜尋與 X 或 Y 相關的結果。 jobs OR gates | 與 OR 相同。 jobs | gates AND 搜尋與 X 與 Y 相關的結果。 jobs AND gates - 排除包含特定字詞或片語的結果。 jobs -apple * 萬用字元,可匹配任何字詞或片語。 steve * apple ( ) 將多個搜尋條件分組。 (ipad OR iphone) apple define: 查詢字詞或片語的定義。 define:entrepreneur cache: 查看網頁的最新快取版本。 cache:apple.com filetype: 搜尋特定檔案類型(例如 PDF)。 apple filetype:pdf ext: 與 filetype: 相同。 apple ext:pdf site: 只搜尋特定網站的結果。 site:apple.com related: 搜尋與指定網域相關的網站。 related:apple.com intitle: 搜尋標題包含特定字詞的頁面。 intitle:apple allintitle: 搜尋標題包含多個字詞的頁面。 allintitle:apple iphone inurl: 搜尋 URL 中包含特定字詞的頁面。 inurl:apple allinurl: 搜尋 URL 中包含多個字詞的頁面。 allinurl:apple iphone intext: 搜尋內容包含特定字詞的頁面。 intext:apple iphone allintext: 搜尋內容包含多個字詞的頁面。 allintext:apple iphone weather: 查詢某個地點的天氣。 weather:san francisco stocks: 查詢股票代碼的股價資訊。 stocks:aapl map: 強制顯示地圖結果。 map:silicon valley movie: 搜尋電影資訊。 movie:steve jobs in 單位換算。 $329 in GBP source: 在 Google 新聞中搜尋特定來源的結果。 apple source:the_verge before: 搜尋特定日期之前的結果。 apple before:2007-06-29 after: 搜尋特定日期之後的結果。 apple after:2007-06-29 不穩定 搜尋運算子 用途 範例 #..# 搜尋數字範圍內的結果。 iphone case $50..$60 inanchor: 搜尋反向連結錨點文字包含特定字詞的頁面。 inanchor:apple allinanchor: 搜尋反向連結錨點文字包含多個字詞的頁面。 allinanchor:apple iphone AROUND(X) 搜尋兩個字詞或片語在彼此 X 個字以內的頁面。 apple AROUND(4) iphone loc: 搜尋指定地區的結果。 loc:"san francisco" apple location: 在 Google 新聞中搜尋特定地點的新聞。 location:"san francisco" apple daterange: 搜尋特定日期範圍的結果。 daterange:11278-13278 不可用(Google 已正式移除) 搜尋運算子 用途 範例 ~ 包含同義詞(2013 已移除)。 ~apple + 搜尋包含精確字詞或片語的結果(2011 已移除)。 jobs +apple inpostauthor: 在 Google Blog Search 中搜尋特定作者的文章(已停止)。 inpostauthor:"steve jobs" allinpostauthor: 與 inpostauthor: 相同,但不需要加引號。 allinpostauthor:steve jobs inposttitle: 在已停用的 Google Blog Search 中搜尋標題包含特定字詞的文章。 inposttitle:apple iphone link: 搜尋連到特定網域或 URL 的頁面(2017 已移除)。 link:apple.com info: 查詢特定頁面或網站的資訊(2017 已移除)。 info:apple.com id: 與 info: 相同。 id:apple.com phonebook: 搜尋某人的電話號碼(2010 已移除)。 phonebook:tim cook # 在 Google+ 上搜尋主題標籤(2019 已移除)。 #apple

Hero Image
SSH 证书登录教程

SSH 证书登录教程 证书登录的流程 SSH 证书登录之前,如果还没有证书,需要生成证书。具体方法是: 用户和服务器都将自己的公钥,发给 CA CA 使用服务器公钥,生成服务器证书,发给服务器 CA 使用用户的公钥,生成用户证书,发给用户。 有了证书以后,用户就可以登录服务器了。整个过程都是 SSH 自动处理,用户无感知。 用户登录服务器时,SSH 自动将用户证书发给服务器。 服务器检查用户证书是否有效,以及是否由可信的 CA 颁发。 SSH 自动将服务器证书发给用户。 用户检查服务器证书是否有效,以及是否由信任的 CA 颁发。 双方建立连接,服务器允许用户登录。 生成 CA 的密钥 虽然 CA 可以用同一对密码签发用户证书和服务器证书,但是出于安全性和灵活性,最好用不同的密钥分别签发。所以,CA 至少需要两对密钥,一对是签发用户证书的密钥,假设叫做 user_ca,另一对是签发服务器证书的密钥,假设叫做 host_ca。 # 生成 CA 签发用户证书的密钥 # 会在~/.ssh目录生成一对密钥:user_ca(私钥)和user_ca.pub(公钥) # 各个参数含义如下 # -t rsa:指定密钥算法 RSA。 # -b 4096:指定密钥的位数是4096位。安全性要求不高的场合,这个值可以小一点,但是不应小于1024。 # -f ~/.ssh/user_ca:指定生成密钥的位置和文件名。 # -C user_ca:指定密钥的识别字符串,相当于注释,可以随意设置。 $ ssh-keygen -t rsa -b 4096 -f ~/.ssh/user_ca -C user_ca # 生成 CA 签发服务器证书的密钥 # 会在~/.ssh目录生成一对密钥:host_ca(私钥)和host_ca.pub(公钥) # 现在,~/.ssh目录应该至少有四把密钥。 # - ~/.ssh/user_ca # - ~/.ssh/user_ca.pub # - ~/.ssh/host_ca # - ~/.ssh/host_ca.pub $ ssh-keygen -t rsa -b 4096 -f host_ca -C host_ca 服务器安装 CA 公钥 # 为了让服务器信任用户证书,必须将 CA 签发用户证书的公钥`user_ca.pub`,拷贝到服务器 $ scp ~/.ssh/user_ca.pub root@host.example.com:/etc/ssh/ 然后,将下面一行添加到服务器配置文件 /etc/ssh/sshd_config TrustedUserCAKeys /etc/ssh/user_ca.pub 上面的做法是将user_ca.pub加到/etc/ssh/sshd_config,这会产生全局效果,即服务器的所有账户都会信任user_ca签发的所有用户证书。