伺服器安全規範,伺服器規範
ssh 登入驗證:使用公開金鑰和Google認證
server 端 設定檔
Port 3208Protocol 2ListenAddress 0.0.0.0SyslogFacility AUTHPRIVRSAAuthentication yesPubkeyAuthentication yesPermitRootLogin noPermitEmptyPasswords noPasswordAuthentication yesChallengeResponseAuthentication noGSSAPIAuthentication no#是否在使用者退出登入後自動銷毀使用者憑證緩衝GSSAPICleanupCredentials yesUsePAM yesAcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGESAcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENTAcceptEnv LC_IDENTIFICATION LC_ALLX11Forwarding noUseDNS noClientAliveInterval 60Subsystem sftp /usr/libexec/openssh/sftp-server
client端設定檔
Port 3208Protocol 2ListenAddress ipSyslogFacility AUTHPRIVPermitRootLogin noPermitEmptyPasswords noPasswordAuthentication yesChallengeResponseAuthentication noGSSAPIAuthentication noGSSAPICleanupCredentials yesUsePAM yesAcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGESAcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENTAcceptEnv LC_IDENTIFICATION LC_ALLX11Forwarding noUseDNS noClientAliveInterval 60Subsystem sftp /usr/libexec/openssh/sftp-server
1.產生公開金鑰與私密金鑰
ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/client/.ssh/id_rsa): #此處直接按斷行符號即可Created directory '/home/client/.ssh'.Enter passphrase (empty for no passphrase): #此處直接按斷行符號即可Enter same passphrase again: #此處直接按斷行符號即可Your identification has been saved in /home/client/.ssh/id_rsa.Your public key has been saved in /home/client/.ssh/id_rsa.pub.
2. 將公開金鑰檔案追加到server端使用者目錄的./ssh/authorized_keys中 ,.ssh目錄許可權必須是0700
cat id_rsa.pub >> authorized_keyschmod 600 authorized_keys
3.server 端 和client 端 無密碼登入
scp ./id_rsa.pub sweet@192.168.1.101:/home/sweet/.ssh/authorized_keys#注意一下目標機的authorized_keys的許可權是-rw-r--r--,如果不是需要執行chmod 644 authorized_keys修改檔案的許可權
Google驗證器
安裝GOOGLE-AUTHENTICATOR驗證器1.安裝epel源rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm2.安裝git級二維碼工具yum install -y git qrencode3.安裝開發包工具yum groupinstall -y "Development Tools" pam-devel4.安裝google-authenticatorgit clone https://github.com/google/google-authenticator.gitcd google-authenticator/libpam/sh bootstrap.sh./configure && make && make installcp -v /usr/local/lib/security/pam_google_authenticator.so /lib64/security/5.產生基於計數的認證token(可以忽略時間錯誤)google-authenticator(n,y,y,y)6.更改ssh級pam設定## 修改PAMvi /etc/pam.d/sshdauth required pam_google_authenticator.so## 修改SSH配置ChallengeResponseAuthentication yesUsePAM yesservice sshd restart修改ssh的鑒權方式,改為鍵盤互動。注意: 這裡要把應急驗證碼記錄下,防止驗證壞掉以後無法登陸,也可以把ssh的公開金鑰下載下來做備用登陸方式