SSH için şifre kimlik doğrulamasını devre dışı bırakın


127

SSH istemcilerinin burada belirtildiği gibi parola istemine erişmesini engellemenin bir yolunu arıyorum .

Kök oturum açmapassword: istemini devre dışı bırakamıyorum . sshd_configDosyayı okumak için değiştirdim :

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

ve ayrıca izinleri değiştirdi chmod 700 ~/.sshve chmod 600 ~/.ssh/authorized_keys. Neyi kaçırıyorum? Bunun için bir parola olmam gerekiyor mu?

Ayrıntılı döküm:

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Next authentication method: password

Dosya / etc / ssh / sshd_config:

# 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 no
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

ssh -v user @ server, sorunu gidermenize yardımcı olacak ayrıntılı çıktı almak için.
— Niall Byrne

Hem ssh_configve sshd_configvar PasswordAuthentication- kalmak keskin!
— Brent Bradburn

Yanıtlar:


199

Dosyada /etc/ssh/sshd_config

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

İkinci satırın açıklamasını kaldırın ve gerekirse evet'i hayır olarak değiştirin.

O zaman koş

service ssh restart

7
Birçok kılavuz sunucuda ChallengeResponseAuthentication, PasswordAuthentication, UsePAM'in yes'ten no'ya değiştirilmesini önermektedir. Debian / Ubuntu altında başarıyla test edildi.

10
Bilginize, hizmeti yeniden başlatmanın sistemsel yolu şudur: systemctl restart sshdBu, daha yeni Ubuntu'da varsayılandır.
— therealjumbo

Parola doğrulama devre dışı bırakılırken sunucuya nasıl yeni anahtarlar eklerim? Elbette, şifre doğrulamayı açmak zorunda kalmadan bunu yapmanın bir yolu vardır, birisi her anahtar eklemek isterse ...
— Matthew

1
@Matthew Belki kullanıyorssh-copy-id
— iamyojimbo

@iamyojimbo, ancak bu komutla bağlanıp bir tane gönderebilmek için hala yetkili bir anahtara ihtiyacınız var.
— Matthew

16

Çalıştırmak

service ssh restart

onun yerine

/etc/init.d/ssh restart

Bu işe yarayabilir.


Bu benim için çalıştı; init.d'yi kullanmanın neden olmadığı hakkında bir fikriniz var mı?
— Seb

1
Senin linux lezzetine bağlı ... Gentoo'da ikisi de benim için çalışıyor.
— Gene Pavlovsky

16

İşte bunu otomatik olarak yapacak bir komut dosyası

# Only allow key based logins
sed -n 'H;${x;s/\#PasswordAuthentication yes/PasswordAuthentication no/;p;}' /etc/ssh/sshd_config > tmp_sshd_config
cat tmp_sshd_config > /etc/ssh/sshd_config
rm tmp_sshd_config

3

Bu adımları takip ettim (Mac için).

In /etc/ssh/sshd_configdeğişikliği

#ChallengeResponseAuthentication yes
#PasswordAuthentication yes

için

ChallengeResponseAuthentication no
PasswordAuthentication no

Şimdi RSA anahtarını oluşturun:

ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

(Benim için bir RSA anahtarı çalıştı. Bir DSA anahtarı çalışmadı.)

(Genel anahtar) ~/.ssh/id_rsaile birlikte özel bir anahtar oluşturulacaktır ~/.ssh/id_rsa.pub.

Şimdi .ssh klasörüne gidin:cd ~/.ssh

Girin rm -rf authorized_keys(bazen birden çok anahtar hataya yol açar).

Giriş vi authorized_keys

:wqBu boş dosyayı kaydetmek için girin

Giriş cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

SSH'yi yeniden başlatın:

sudo launchctl stop com.openssh.sshd
sudo launchctl start com.openssh.sshd

touchBoş dosyayı oluşturmak için kullanamaz authorized_keysmısınız?
— Peter Mortensen

-8

Bu, sahip olduğum bir öğreticiden:

Makinenizde root olarak:

ssh-keygen -t rsa

Ve parolayı boş bırakın.

Yerel makinenizden (ve bir parola yazmanız gerekecektir):

ssh root@remotemachine mkdir -p .ssh

Sonra:

cat .ssh/id_rsa.pub | ssh root@remotemachine 'cat >> .ssh/authorized_keys'

Artık parola istemeden giriş yapabilirsiniz

ssh root@remotemachine

Herhangi bir sorunla karşılaşırsanız SSH girişini şifre olmadan görün !


2
Her durumda parola isteminin gelmesini engellemek istiyorum. Yalnızca ssh anahtarıyla oturum
— Matt Stokes

Bunu yapmalı. Sizden bir şifre istemeden, ancak belirli bir istemciden doğrudan açılacaktır.
— Fabrizio Mazzoni

1
evet, ancak bu aynı zamanda bir parola denemeye yetkili olmayan istemcilere de izin verecek, değil mi?
— Matt Stokes

Aşağıdakileri değiştirin: ChallengeResponseAuthentication no, PasswordAuthentication no, UsePAM no Bu yalnızca anahtar kimlik doğrulamasına izin verir. Sadece sistemimde test edildi ve şu şekilde reddedecek: İzin reddedildi (genel anahtar)
— Fabrizio Mazzoni

1
Gönderdiğiniz dosya gerçek yapılandırmaysa, PasswordAuthentication bölümünün açıklamasını
— kaldırmadınız
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.