Pagina 1 di 1

[Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: sabato 26 febbraio 2011, 20:50
da adamquadmon
Sono giorni che ci provo, sto installando git sul server ma non mi funziona l'autenticazione

ho creato l'utente git in questo modo

$ sudo adduser \
      --system \
      --shell /bin/sh \
      --gecos 'git version control' \
      --group \
      --disabled-password \
      --home /home/git \
      git

questo utente ha la pasword disabilitata

ho caricato la chiave pubblica in /home/git/.ssh/autorized_keys

quando provo a loggarmi mi chiede la password che però non c'è (non c'è nemmeno la passphrase in quanto git richiede che non ci sia).

questo è l'output del comando ssh -v git@nomehost.tld

dove nomehost.tld è il dominio del server
e User è l'account su Win 7 dal quale lancio il comando

Codice: Seleziona tutto

$ ssh -v git@nomehost.tld
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to git@nomehost.tld [iphost] port 22.
debug1: Connection established.
debug1: identity file /c/Users/User/.ssh/identity type -1
debug1: identity file /c/Users/User/.ssh/id_rsa type -1
debug1: identity file /c/Users/User/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debia
n-3ubuntu3
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'git@nomehost.tld' is known and matches the RSA host key.
debug1: Found key in /c/Users/User/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/User/.ssh/identity
debug1: Trying private key: /c/Users/User/.ssh/id_rsa
debug1: Offering public key: /c/Users/User/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
git@nomehost.tld password:
questo è il contenuto di /etc/ssh/sshd_config:

Codice: Seleziona tutto

vi: /usr/local/lib/libz.so.1: no version information available (required by /usr/lib/libpython2.6.so.1.0)
# 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
#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 yes
AllowUsers root
AllowUsers git

Potrebbe essere una questione di permessi?
Non ne ho idea.
Help please!

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: sabato 26 febbraio 2011, 20:53
da saxtro
se l' hai messa qua  /home/git/.ssh/autorized_keys
non ti funziona per un errore d' ortografia

/home/git/.ssh/authorized_keys

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 0:32
da adamquadmon
la locazione esatta è quella corretta: authorized_keys
ho sbagliato a scrivere nel post non sul server, non è quello l'errore purtroppo

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 9:29
da ReMichael
prova a specificare gli allowusers sulla stessa linea:

Codice: Seleziona tutto

AllowUsers root git

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 10:27
da adamquadmon
ho messo tutto su una riga ho riavviato il servizio ma non cambia niente

quando ho riavviato però è uscito questo, non so se  incide:

Codice: Seleziona tutto

/etc/init.d/ssh restart
mkdir: cannot create directory `/var/run/proftpd': File exists
 * Restarting OpenBSD Secure Shell server sshd
aggiungo un'altra cosa,
questo è l'output del comando ps -A | grep sshd:

Codice: Seleziona tutto

# ps -A | grep sshd
 3394 ?        00:00:00 sshd
 3965 ?        00:00:00 sshd
10114 ?        00:00:00 sshd
28482 ?        00:00:00 sshd
e questo il risultato di sudo netstat --inet -lpn | grep sshd:

Codice: Seleziona tutto

# sudo netstat --inet -lpn | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN                                        3394/sshd
il demone runna ma le authorized_keys non se le c**a nemmeno di striscio

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 10:43
da ReMichael
Non credo che l'errore di proftpd c'entri qualcosa (anche se mi chiedo perché esce quando restarti ssh).

Controlla se hai qualche info in più nel file di log auth.log e i permessi della .ssh e del file authorized_keys

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 11:32
da adamquadmon
Allora,
auth.log non si trova, ho trovato questo però /var/log/directadmin/security.log.
l'ultima riga (corrispondente al mio ultimo tentativo di loggin tramite client) dice:

2011:02:28-10:55:14: Found one of block_token_chars in token grep= from [iiNumber] with request /CMD_LOG_VIEWER

Codice: Seleziona tutto

/home/git# ls -la .ssh/
total 12
d--------- 2 git git 4096 2011-02-26 21:45 .
drwxr-xr-x 4 git git 4096 2011-02-23 12:32 ..
---------- 1 git git 2809 2011-02-26 19:34 authorized_keys
dopo chmod 700 .ssh e chmod 600 .ssh/authorized_keys
sembra che qualcosa sia cambiato.
Ora tentando il login da client ottengo:

Codice: Seleziona tutto

$ ssh -v git@myHost.tld
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to myHost.tld [ipHost] port 22.
debug1: Connection established.
debug1: identity file /c/Documents and Settings/User/.ssh/identity type -1
debug1: identity file /c/Documents and Settings/User/.ssh/id_rsa type 1
debug1: identity file /c/Documents and Settings/User/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debia
n-3ubuntu3
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'myHost.tld' is known and matches the RSA host key.
debug1: Found key in /c/Documents and Settings/User/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Documents and Settings/User/.ssh/identity
debug1: Offering public key: /c/Documents and Settings/User/.ssh/id_rsa
debug1: Remote: Forced command: python /home/user/libs/indefero/scrip
ts/gitserve.py user
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Remote: Forced command: python /home/user/libs/indefero/scrip
ts/gitserve.py f
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
python: /usr/local/lib/libz.so.1: no version information available (required by
python)
Need SSH_ORIGINAL_COMMAND in environment.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to myHost.tld closed.
debug1: Transferred: stdin 0, stdout 0, stderr 41 bytes in 0.1 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 328.0
debug1: Exit status 1
Guardando le ultime righe leggo:
debug1: Authentication succeeded (publickey).
poi un avviso che incontro spesso sul server:
python: /usr/local/lib/libz.so.1: no version information available (required by
python) Need SSH_ORIGINAL_COMMAND in environment.

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 12:20
da ReMichael
Credo ci sia qualcosa che non va a livello di sistema..

Codice: Seleziona tutto

sudo apt-get update
sudo apt-get upgrade
ti da qualche errore di dipendenza o pacchetti non configurati?

Anzi.. leggi prima qui:
http://projects.ceondo.com/p/indefero/issues/198/

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 12:54
da adamquadmon
Quel post lo avevo letto, fa capo ad una vecchia revisione, quella che ho installato io gia contiene la patch, almeno per quanto ho potuto comprendere.

Ho aggiornato il software con apt-get, c'erano dei pacchetti di openssh da aggiornare. Ma nulla è cambiato.

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 20:58
da saxtro
Nel man di sshd c'è scritto questo:

Codice: Seleziona tutto

AUTHORIZED_KEYS FILE FORMAT
     AuthorizedKeysFile specifies the file containing public keys for public
     key authentication; if none is specified, the default is
     ~/.ssh/authorized_keys.  Each line of the file contains one key (empty
     lines and lines starting with a ‘#’ are ignored as comments).  Protocol 1
     public keys consist of the following space-separated fields: options,
     bits, exponent, modulus, comment.  Protocol 2 public key consist of:
     options, keytype, base64-encoded key, comment.  The options field is
     optional; its presence is determined by whether the line starts with a
     number or not (the options field never starts with a number).  The bits,
     exponent, modulus, and comment fields give the RSA key for protocol ver‐
     sion 1; the comment field is not used for anything (but may be convenient
     for the user to identify the key).  For protocol version 2 the keytype is
     “ssh-dss” or “ssh-rsa”.

     Note that lines in this file are usually several hundred bytes long
     (because of the size of the public key encoding) up to a limit of 8 kilo‐
     bytes, which permits DSA keys up to 8 kilobits and RSA keys up to 16
     kilobits.  You don’t want to type them in; instead, copy the
     identity.pub, id_dsa.pub, or the id_rsa.pub file and edit it.

     sshd enforces a minimum RSA key modulus size for protocol 1 and protocol
     2 keys of 768 bits.

     The options (if present) consist of comma-separated option specifica‐
     tions.  No spaces are permitted, except within double quotes.  The fol‐
     lowing option specifications are supported (note that option keywords are
     case-insensitive):

     command="command"
             Specifies that the command is executed whenever this key is used
             for authentication.  The command supplied by the user (if any) is
             ignored.  The command is run on a pty if the client requests a
             pty; otherwise it is run without a tty.  If an 8-bit clean chan‐
             nel is required, one must not request a pty or should specify
             no-pty.  A quote may be included in the command by quoting it
             with a backslash.  This option might be useful to restrict cer‐
             tain public keys to perform just a specific operation.  An exam‐
             ple might be a key that permits remote backups but nothing else.
             Note that the client may specify TCP and/or X11 forwarding unless
             they are explicitly prohibited.  The command originally supplied
             by the client is available in the SSH_ORIGINAL_COMMAND environ‐
             ment variable.  Note that this option applies to shell, command
             or subsystem execution.

qua c'è un esempio su come si usa
http://www.unix.com/solaris/35849-passi ... eters.html

Re: [Server] Accesso ssh tramite chiave pubblica/privata non funziona

Inviato: lunedì 28 febbraio 2011, 23:33
da adamquadmon
RISOLTO!

praticamente non c'entrava niente sta roba qui

per intenderci, questa è una stringa tipo del mio authorized_keys
Indefero si occupa di crearla

Codice: Seleziona tutto

command="python /[...percorso di indefero...]/indefero/scripts/gitserve.py nomeUtente",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa [...chiave...]== Utente@Computer
l'errore lo dava semplicemente perchè nel fare ssh git@nomehost non gli passavo nessun parametro, mentre invece ne vuole necessariamente per gestirli nello script in python

mi sono spiegato una chiavica, ma il succo è che non era quello il problema.

invece di fare
ssh -v git@nomehost
dovevo concentrarmi su
git clone git@nomehost

sopresa delle sorprese:

Indefero non crea i repository da solo (oppure non l'ho configurato bene)
per far funziare il giocattolino si deve creare a mano il repo iniziale:

in /home/git/repositories:
mkdir myrepo.git
cd myrepo.git
git --bare init

ed ora dal client si può fare git clone senza errori


scusatemi se vi ho fatto andare al manicomio appresso a me, grazie dell'attenzione