Pagina 1 di 1

[Risolto] Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 17:10
da robustelli
Buonasera a tutti del forum
ho un problema , e prima di rivolgermi a voi ho letto diversi how-to
senza cavarne un ragno dal buco

Ho un semplicissimo server SSH, al quale vogliono collegarsi con Chiavi condivise SSH
(senza dover immettere passaword)

Installo il demone SSH con questo file di configurazione

Codice: Seleziona tutto

Port 22
Protocol 2
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
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
#PermitRootLogin prohibit-password
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	%h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
UseDNS no
mi collego all' utente che mi serve
nel mio caso "feae"
lancio il comando

Codice: Seleziona tutto

ssh-keygen
lancio ancora il comando

Codice: Seleziona tutto

ssh-copy-id root@Client1
Mi dice pure Chiave aggiunta su Client1

ma quando mi collego sul Client1
e lancio un bel ssh feae@Server
mi cerca la password (una volta inserito funziona)
non dovrebbe loggarsi automaticamente... dove sbaglio ?
avete qualche idea ?

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 17:30
da Filoteo
La chiave pubblica devi copiarla nella home di ogni utente tramite il quale vuoi accedere, non solo l'utente root:

Codice: Seleziona tutto

ssh-copy-id feae@Client1

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 17:53
da robustelli
a me serve solo per root, e non funziona

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 17:57
da Filoteo
Posta l'output di

Codice: Seleziona tutto

ssh -v root@server
e anche

Codice: Seleziona tutto

ls -l .ssh
(quest'ultimo eseguito dal server stesso).

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:17
da robustelli
Last login: Tue Nov 27 16:33:26 2018 from 192.168.1.240
root@ServerMaster:~# ssh -v feae@192.168.1.240
OpenSSH_7.2p2 Ubuntu-4ubuntu2.6, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.240 [192.168.1.240] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubunt u-4ubuntu2.6
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.240:22 as 'feae'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit > compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit > compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Boe5rLHFKIf8+OonzY7LXpUwVKqr VneBJDjxBHCOeqA
debug1: Host '192.168.1.240' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,hostbased
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:18
da robustelli
ls -l .ssh
totale 8
-rw------- 1 root root 800 nov 27 16:24 authorized_keys
-rw-r--r-- 1 root root 222 nov 27 16:30 known_hosts

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:24
da Filoteo
Scusami ma se mi posti l'output di

Codice: Seleziona tutto

ssh -v feae@192.168.1.240
vuole dire che vuoi accedere come utente feae non come utente root! Ergo devi copiare la chiave pubblica così:

Codice: Seleziona tutto

ssh-copy-id feae@192.168.1.240

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:34
da robustelli
hai ragione mi sono spiegato male, e scusami per questo,

Situazione
Server SSH con Utente Feae
Client SSH con Utente Root

Client Root ... deve collegarsi su Feae Server

quindi ...

Genero La Chiave Su Server Su Utente feae
copio da Server A Client La Chiave ssh-copy-id feae@192.168.1.250
Provo la connessione da client
da root client ... ssh feae@192.168.1.240
non va

l'errore stà che devo copiare dal Client ? e non dal server ?

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:41
da Filoteo
No, è il contrario, devi generare la coppia di chiavi sul computer DAL quale vuoi connetterti (Client) e poi copiare la chiave pubblica con ssh-copy-id nella home del computer AL quale vuoi connetterti (Server).

Re: Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 18:43
da robustelli
errore mio
grazie mille

Re: [Risolto] Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 19:18
da Stealth
A margine ma non troppo, vai a cancellare quella riga nel file di configurazione del server

Codice: Seleziona tutto

PermitRootLogin yes
e poi riavvia il servizio perchè recepisca la modifica, che è meglio :ciao:
ciao

Re: [Risolto] Connessione Con Chiavi SSH

Inviato: martedì 27 novembre 2018, 20:19
da Filoteo
Non dovrebbe essere necessario in quanto prohibit-password già presente dovrebbe consentire l'accesso solo tramite chiavi ssh.

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 9:54
da robustelli
Purtroppo il problema non è stato risolto, credevo di aver combinato io un casino e quindo ho preferito ricreare il server da zero
ringrazio innanzitutto Filoteo per l' aiuto Ma purtroppo anche facendo come lui suggerito Continua a chiedere la password

Ricapitolo I Passaggi Fatti

1. Installazione SSH con questo File di configurazione Sul Server

Codice: Seleziona tutto

Port 22
Protocol 2
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
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	%h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
UseDNS no

2.
Creo utente Su Server feae con home: /home/feae

3.
Su Client Creo Chiave Pubblica ssh-keygen

4. copio il id_rsa.pub creato sul client in manuale e lo incollo sul server
aggiungo a /home/feae/.ssh/authorized_keys

5.
Riavvio Il Servizio sul Server

6.
Su Client lancio ssh@server
mi chiede password

:muro: :muro: :muro: :muro: :muro:

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 10:07
da Filoteo
Esegui sul client:

Codice: Seleziona tutto

ls -ld .ssh
ls -l .ssh
ssh -v feae@server
Sul server:

Codice: Seleziona tutto

ls -ld .ssh
ls -l .ssh
Posta gli output usando il tag "Codice" includendo anche il comando che stai eseguendo.

Aggiungo anche questo per il server

Codice: Seleziona tutto

grep sshd /var/log/auth.log | tail -10

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 10:12
da Stealth
Non ho molto tempo e ti passo questo al volo, è di una centos ma è l'unico che ho sottomano al momento. Funziona bene da anni e solo con chiave, ma possono esserci differenze. Vedi te se può servire a qualcosa, anche solo come spunto
ciao

Codice: Seleziona tutto

[root@rubinetto utente]# cat /etc/ssh/sshd_config 
#	$OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm 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:/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 change a
# default value.

Port 22
AddressFamily inet

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# Logging
SyslogFacility AUTHPRIV

# Authentication:
PermitRootLogin no
StrictModes yes

RSAAuthentication yes

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

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

# 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

# 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

UsePrivilegeSeparation no

# Turn on  reverse name checking
UseDNS no

# no default banner path
#Banner none

# 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
[root@rubinetto utente]#

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 12:49
da robustelli
Su client (quello che si deve collegare senza passwor)

Codice: Seleziona tutto

ls -ld .ssh
drwx------ 2 root root 4096 nov 28 09:23 .ssh

Codice: Seleziona tutto

ls -l .ssh
total 12
-rw------- 1 root root 1766 nov 28 09:37 id_rsa
-rw-r--r-- 1 root root  393 nov 28 09:37 id_rsa.pub
-rw-r--r-- 1 root root  222 nov 28 09:23 known_hosts

Codice: Seleziona tutto

ssh -v feae@192.168.1.240
OpenSSH_7.2p2 Ubuntu-4ubuntu2.5, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.240 [192.168.1.240] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.6
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.240:22 as 'feae'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Boe5rLHFKIf8+OonzY7LXpUwVKqrVneBJDjxBHCOeqA
debug1: Host '192.168.1.240' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,hostbased
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
Enter passphrase for key '/root/.ssh/id_rsa':
Su Server

Codice: Seleziona tutto

ls -ld .ssh
drwx------ 2 feae sdiftp 4096 nov 27 18:41 .ssh

Codice: Seleziona tutto

totale 12
-rw------- 1 feae sdiftp 1233 nov 28 10:05 authorized_keys
-rw------- 1 feae sdiftp 1766 nov 27 17:33 id_rsa
-rw------- 1 feae sdiftp  400 nov 27 17:33 id_rsa.pub
il log /var/log/auth.log è vuoto, mi da errore solo se non inserisco password

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 12:55
da Filoteo
Durante la creazione della coppia di chiavi sul client hai specificato una password per proteggere la chiave privata, difatti te la chiede:

Codice: Seleziona tutto

Enter passphrase for key '/root/.ssh/id_rsa':
Si può rimuovere volendo ma facciamo prima se generi una coppia di chiavi nuovi e ricopi la chiave pubblica sul server.

Re: Connessione Con Chiavi SSH

Inviato: mercoledì 28 novembre 2018, 13:02
da robustelli
Chiedo Venia, avete ragione
confermo funziona tutto

Ringrazio Tutto il Forum, per l'auto profuso