linux 遠程rsa 登錄配置 文件 /etc/ssh/sshd_config


linux 創建用戶

useradd ccpit  # 創建ccpit用戶
passwd ccpit  # 給這個用戶設置密碼

修改/etc/ssh/sshd_config文件

#	$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy 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
#ListenAddress 0.0.0.0
#ListenAddress ::

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

# Ciphers and keying
#RekeyLimit default none

# Logging
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
StrictModes no
#MaxAuthTries 6
#MaxSessions 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
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# 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!
#PermitEmptyPasswords no

# 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
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# 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
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel 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
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
UseDNS no
AddressFamily inet
PermitRootLogin no 
SyslogFacility AUTHPRIV
PasswordAuthentication no
AllowUsers ccpit

 在/home/ccpit 下生成ssh_key

 

 把id_rsa 內容復制進authorized_keys (沒有需要先創建authorized_keys文件)

cat id_rsa >> authorized_keys

 

systemctl restart sshd.service

退出重新登錄即可

 

常用選項

UseDNS no
AddressFamily inet
PermitRootLogin no
#SyslogFacility用來設定在記錄來自sshd的消息的時候,是否給出“facility code”
SyslogFacility AUTHPRIV
#PasswordAuthentication用來設置是否開啟密碼驗證機制,如果用密碼登錄系統,則設置yes
PasswordAuthentication no
#指定允許通過遠程訪問的用戶,多個用戶以空格隔開
AllowUsers root
#X11Forwarding 用來設置是否允許X11轉發
X11Forwarding yes
#設置是否通過PAM驗證
UsePAM yes
#GSSAPIAuthentication 指定是否允許基於GSSAPI的用戶認證,默認為no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials 設置是否在用戶退出登錄是自動銷毀用戶的憑證緩存
GSSAPICleanupCredentials no
#ChallengeResponseAuthentication 是否允許質疑-應答(challenge-response)認證
ChallengeResponseAuthentication no

#RSAAuthentication用來設置是否開啟RSA密鑰驗證
RSAAuthentication yes
#PubkeyAuthentication用來設置是否開啟公鑰驗證,如果使用公鑰驗證的方式登錄時,則設置為yes
PubkeyAuthentication yes
#AuthorizedKeysFile用來設置公鑰驗證文件的路徑,與PubkeyAuthentication配合使用,默認值是".ssh/authorized_keys"
AuthorizedKeysFile      .ssh/authorized_keys

#StrictModes用來設置ssh在接收登錄請求之前是否檢查用戶根目錄和rhosts文件的權限和所有權
StrictModes no
#MaxAuthTries 用來設置最大失敗嘗試登陸次數為6
#MaxAuthTries 6

  


免責聲明!

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



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