linux配置ssh某用戶只允許證書登陸


1,客戶端

生成公鑰與私鑰

ssh-keygen -t rsa -C ‘email’ -f ~/.ssh/user_ssh

然后會在~/.ssh生成user_ssh, user_ssh.pub

2,服務端

user登錄服務端,並上傳user_ssh.pub到服務端

配置ssh

touch ~/.ssh/authorized_keys 

cat user_ssh.pub >> ~/.ssh/authorized_keys 

sudo /etc/init.d/ssh start
 

禁止root賬戶並禁止所有用戶密碼登錄

# Subsystem sftp /usr/lib/openssh/sftp-server  #關閉sftp

# 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
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
UseDNS no
AddressFamily inet
PermitRootLogin no  #禁止root
SyslogFacility AUTHPRIV
PasswordAuthentication no #禁止密碼方式驗證

 

 

3, 客戶端測試  

使用xshell, 指定服務器信息之后,在驗證設置中選擇使用驗證方法為public key

輸入用戶名, 選擇我們在客戶端生成的密鑰, 如果生成公鑰與私鑰時候有輸入通行密碼即passphrase這里也要輸入

然后就以”免密碼“ 方式可以登錄了。

我們再使用用戶名密碼ssh user@host這種方法登錄則會如下圖提示。

  

 

:D

以上個人簡單筆記


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM