Disabilita l'autenticazione della password per SSH


127

Sto cercando un modo per disabilitare i client SSH dall'accesso al prompt della password come indicato qui .

Non riesco a disabilitare il password:prompt per l' accesso come root . Ho cambiato il sshd_configfile da leggere:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

e hanno anche cambiato le autorizzazioni chmod 700 ~/.sshe chmod 600 ~/.ssh/authorized_keys. Cosa mi manca? È necessario disporre di una passphrase?

Dump dettagliato:

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

File / 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 utente @ server per ottenere un output dettagliato per aiutarti a risolvere i problemi.
— Niall Byrne

Entrambi ssh_confige sshd_confighanno PasswordAuthentication- resta forte!
— Brent Bradburn

Risposte:


199

Nel file /etc/ssh/sshd_config

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

Rimuovere il commento dalla seconda riga e, se necessario, modificare da sì a no.

Allora corri

service ssh restart

7
Molte guide suggeriscono di cambiare ChallengeResponseAuthentication, PasswordAuthentication, UsePAM da sì a no sul server. Testato con successo in Debian / Ubuntu.

9
Cordiali saluti, il modo systemd per riavviare il servizio è: systemctl restart sshdQuesta è l'impostazione predefinita su Ubuntu più recente.
— therealjumbo

Come aggiungo nuove chiavi al server, mentre l'autenticazione della password è disabilitata? Sicuramente c'è un modo per farlo, senza dover attivare l'autenticazione della password, ogni volta che qualcuno vuole aggiungere una chiave ...
— Matteo

1
@Matthew Forse usandossh-copy-id
— iamyojimbo

@iamyojimbo ma hai ancora bisogno di una chiave autorizzata per poterti connettere e inviarne una con quel comando.
— Matteo

16

Correre

service ssh restart

invece di

/etc/init.d/ssh restart

Questo potrebbe funzionare.


Questo ha funzionato per me; qualche idea sul perché non usare init.d?
— Seb

1
Dipende dal tuo gusto Linux ... Su Gentoo funzionano entrambi per me.
— Gene Pavlovsky

15

Ecco uno script per farlo automaticamente

# 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

Ho seguito questi passaggi (per Mac).

In /etc/ssh/sshd_configcambiamento

#ChallengeResponseAuthentication yes
#PasswordAuthentication yes

per

ChallengeResponseAuthentication no
PasswordAuthentication no

Ora genera la chiave RSA:

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

(Per me una chiave RSA ha funzionato. Una chiave DSA non ha funzionato.)

Una chiave privata verrà generata ~/.ssh/id_rsainsieme a ~/.ssh/id_rsa.pub(chiave pubblica).

Ora spostati nella cartella .ssh :cd ~/.ssh

Invio rm -rf authorized_keys(a volte più chiavi portano a un errore).

accedere vi authorized_keys

Invio :wqper salvare questo file vuoto

accedere cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Riavvia SSH:

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

Non puoi usare touchper creare il file vuoto authorized_keys?
— Peter Mortensen

-8

Questo è tratto da un tutorial che ho:

Sulla tua macchina come root:

ssh-keygen -t rsa

E lascia la passphrase vuota.

Dalla tua macchina locale (e dovrai digitare una password):

ssh root@remotemachine mkdir -p .ssh

Poi:

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

Ora puoi accedere senza richiedere la password

ssh root@remotemachine

Vedi login SSH senza password in caso di problemi!


2
Sto cercando di bloccare la richiesta della password in ogni circostanza. Accesso forzato solo tramite chiave ssh
— Matt Stokes

Questo dovrebbe bastare. Si aprirà direttamente senza richiedere una password ma da un client specifico.
— Fabrizio Mazzoni

1
si ma questo consentirà anche ai client non autorizzati di tentare una password, no?
— Matt Stokes

Modificare quanto segue: ChallengeResponseAuthentication no, PasswordAuthentication no, UsePAM no Ciò consentirà solo l'autenticazione della chiave. Appena testato sul mio sistema e negherò con: Permission denied (public key)
— Fabrizio Mazzoni

1
Non hai decommentato la sezione PasswordAuthentication se il file che hai postato è la configurazione attuale
— Fabrizio Mazzoni
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.