मैं SSH को केवल एक कुंजी के साथ उपयोगकर्ताओं को लॉग इन करने की अनुमति देने के लिए कैसे बाध्य करता हूं?


73

मैंने यहां दिए गए निर्देशों का पालन करने की कोशिश की: http://lani78.wordpress.com/2008/08/08/generate-a-ssh-key-and-disable-password-authentication-on-ubuntu-server/

केवल सर्वर पर सार्वजनिक कुंजी वाले उपयोगकर्ताओं को प्रमाणित करने की अनुमति दें, लेकिन मुझे केवल उपयोगकर्ता नाम या पासवर्ड के साथ लॉगिंग को अस्वीकार करने के लिए SSH नहीं मिल सकता है।

यहाँ मेरी sshd_config फ़ाइल है - क्या मुझे कुछ याद आ रहा है? मैंने पहले से ही SSH और कंप्यूटर को पुनः आरंभ करने का प्रयास किया।

# Package generated configuration file
# See the sshd_config(5) manpage for details


# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# 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
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes


# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768


# Logging
SyslogFacility AUTH
LogLevel INFO


# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes


RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile        %h/.ssh/authorized_keys


# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes


# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no


# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no


# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication no


# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes


# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes


X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no


#MaxStartups 10:30:60
#Banner /etc/issue.net


# Allow client to pass locale environment variables
AcceptEnv LANG LC_*


Subsystem sftp /usr/lib/openssh/sftp-server


# 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'.
UsePAM no

1
FYI करें: वास्तव में sshd पुनरारंभ वास्तव में आवश्यक नहीं है। कमांड /etc/inid.d/ssh रीलोड पर्याप्त होना चाहिए।
ओलिव

#AuthorizedKeysFile को अनसुना करना और सार्वजनिक कुंजी को कॉपी करना न भूलें ~ / .ssh / अधिकृत_की (और पुनः आरंभ)। इसके बिना, यह काम नहीं करेगा।
ivanleoncz

यदि यह 2016 में सच नहीं था, तो निश्चित रूप से 2019 में मामला फिर से शुरू होगा; पुनः लोड करना पर्याप्त नहीं है।
केडीएन

जवाबों:


98

डिफ़ॉल्ट रूप PasswordAuthenticationसे हां पर सेट किया जाता है , भले ही आप इसे टिप्पणी करें /etc/ssh/sshd_config

आपको PasswordAuthentication noकेवल सार्वजनिक कुंजी प्रमाणीकरण की अनुमति देने के लिए स्पष्ट रूप से सेट करना होगा।

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no

नोट (आदमी sshd_config): PasswordAuthentication निर्दिष्ट करता है कि पासवर्ड प्रमाणीकरण की अनुमति है या नहीं। डिफ़ॉल्ट हाँ है।

और sshd service ssh restart(पूर्व systemd माइग्रेशन) या को पुनः आरंभ करें systemctl restart sshd.service


6
इसके अलावा हमारे पास होना चाहिएUsePAM no
Konstantinos

@ पीडोसॉरस क्यों? ये किस काम के लिए अच्छा है?
जनवरी-GLX

1
@ मैं चीजों को सरल रखना पसंद करता हूं और मैं PAM का उपयोग नहीं करना पसंद करता हूं। लेकिन कोई व्यक्ति ठीक से कॉन्फ़िगर PAM प्रमाणीकरण का उपयोग कर सकता है। मुझे लगता है कि यह लिंक ज्ञानवर्धक है: arlimus.github.io/articles/usepam
Konstantinos

1
ChallengeResponseAuthentication को अक्षम करने पर भी विचार करें, superuser.com/a/374234/2879 देखें ।
जिक

13

SSH कुंजियों और इस उत्तर के बारे में इस विकि पृष्ठ के अनुसार , आपको इन दो पंक्तियों को अपने में बदलने की आवश्यकता है :sshd_config

PasswordAuthentication no
ChallengeResponseAuthentication no

1
चुनौती की प्रतिक्रिया के बारे में दूसरी पंक्ति में क्या अंतर है?
रयान बर्नेट

1
"यह" अतिरिक्त सुरक्षा प्रदान नहीं करता है, "प्रति से।" चैलेंजरसेप्टऑथेंटिकेशन "शब्द केवल एक OpenHH कॉन्फ़िगरेशन कीवर्ड है; यह SSH प्रोटोकॉल में" कीबोर्ड-इंटरैक्टिव "userauth पद्धति को संदर्भित करता है -रिचर्ड सिल्वरमैन (Fixunix.com)
pzkpfw

4

में /etc/ssh/sshd_config, नीचे दी गई सेटिंग मेरे लिए काम किया:

PasswordAuthentication no
UsePAM no

अंत में, sshdडेमॉन को पुनः आरंभ करें ।


3

आप जो लाइन चाहते हैं वह sshd_config फ़ाइल में डिफ़ॉल्ट रूप से असामान्य रूप से टिप्पणी की गई है।

# Change to no to disable tunnelled clear text passwords
--->#PasswordAuthentication yes

पासवर्ड को अक्षम करने के लिए, टिप्पणीyes को बदलें noऔर निकालें :

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

1

से https://www.ssh.com/ssh/copy-id#sec-How-ssh-copy-id-works : आम तौर पर, उपयोगकर्ता के घर निर्देशिका या किसी फ़ाइल या निर्देशिका युक्त कुंजी फ़ाइलों को किसी और के द्वारा लिखने योग्य नहीं होना चाहिए । अन्यथा कोई अन्य व्यक्ति उपयोगकर्ता के लिए नई अधिकृत कुंजी जोड़ सकता है और पहुँच प्राप्त कर सकता है। निजी कुंजी फ़ाइलों को किसी और द्वारा पढ़ने योग्य नहीं होना चाहिए।

उपयुक्त के रूप में sudo chmod go-rwx /home/username/प्रतिस्थापित करने का प्रयास करें username

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.