1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
my $SSH2 = Net::SSH2 -> new();
my $Server_Adresse = "XXX.XX.XX.XX";
my $Nutzer = "root";
my $PW = "XXXXXXXX";
# $SSH2 -> connect( $Server_Adresse ) or die "Keine Verbindung zu Host - Adresse $@" , "\n";
# $SSH2 -> auth_password( $Nutzer , $PW ) or die "Fehler bei der Anmeldung $@" , "\n";
# --------------------------------------------------------------------------------------------
print "\n";
my $SSH2_Authentifizierung;
if ( $SSH2 -> connect( "$Server_Adresse" ) )
{
$SSH2_Authentifizierung = $SSH2 -> auth_publickey ( 'root' ,
'/root/.ssh/id_rsa.pub' ,
'/root/.ssh/id_rsa' ,
''
);
}
if ( $SSH2_Authentifizierung && $SSH2 -> auth_ok )
{
print "Success";
}
else { print join ", " , $SSH2 -> error; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/usr/bin/perl use strict; use warnings; use 5.010; my $HOME = $ENV{HOME}; use Net::SSH2; my $SSH2 = Net::SSH2->new(); my $Server_Adresse = "mein-soervaer.deh"; my $Nutzer = "root"; my $PW = "test4711"; my $SSH2_Authentifizierung; if ( $SSH2->connect($Server_Adresse) ) { $SSH2_Authentifizierung = $SSH2->auth_publickey( $Nutzer, "$HOME/.ssh/id_rsa.pub", "$HOME/.ssh/id_rsa", $PW ); } if ( $SSH2_Authentifizierung && $SSH2->auth_ok ) { print "Success"; } else { print join ", ", $SSH2->error; }
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
/root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
1
2
3
4
5
6
7
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD0iXBFi8iuEkyrjMv0mlnBeV+
ZuzNas5boN8EmCXxajegJ3h7zQxlT6spCJsc1FnQUhxSbU77tPvHVAC7uZlmELH
2Bj3HyrGqBM5Mp2BBSBP793LvYOVjiFXK6W6HZ+DZuVbqQYw2hAj4aKZcSwomaz
JNrse7Pvp2hltbglCc9WMnY6UdVJyp9RkBEH/IVbQxrkw7xNVMtPlKMw0qBtgfo
GOSLRi7LsFxUCLtBXexWCHspXU7g9BLyW2n3dvD+xoqjqHzO1C10UvHiI6NXwwA
mO2NW+DeeNeHe3L3A+AXGb3CwXnbUr/6JybxS8wHcaLlfjDz8G99LYje4nUYJql
root@lmeinserver.de
1
2
3
4
5
6
7
8
if ( $SSH2_Authentifizierung && $SSH2 -> auth_ok )
{
print "Success";
}
else { print join ", " , $SSH2 -> error; }
}
sshd -d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: client->server aes128-ctr hmac-sha1 none [preauth]
debug1: kex: server->client aes128-ctr hmac-sha1 none [preauth]
debug1: expecting SSH2_MSG_KEXDH_INIT [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user root service ssh-connection method publickey [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: test whether pkalg/pkblob are acceptable [preauth]
debug1: PAM: initializing for "root"
debug1: PAM: setting PAM_RHOST to "hostname"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /root/.ssh/authorized_keys, line 1 RSA 80:b6:e0:3c:63:fc:0a:10:ce:da:e5:fe:b7:a5:2c:ff
debug1: restore_uid: 0/0
Postponed publickey for root from XXX.XX.XX.XX port 41772 ssh2 [preauth]
Connection closed by XXX.XX.XX.XX [preauth]
debug1: do_cleanup [preauth]
debug1: do_cleanup
debug1: PAM: cleanup
debug1: Killing privsep child 1440
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: client->server aes128-ctr hmac-sha1 none [preauth]
debug1: kex: server->client aes128-ctr hmac-sha1 none [preauth]
debug1: expecting SSH2_MSG_KEXDH_INIT [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user root service ssh-connection method publickey [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: test whether pkalg/pkblob are acceptable [preauth]
debug1: PAM: initializing for "root"
debug1: PAM: setting PAM_RHOST to "hostname"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /root/.ssh/authorized_keys, line 1 RSA 80:b6:e0:3c:63:fc:0a:10:ce:da:e5:fe:b7:a5:2c:ff
debug1: restore_uid: 0/0
Postponed publickey for root from hostname port 41772 ssh2 [preauth]
Connection closed by hostname [preauth]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Use of uninitialized value in split at inc/Devel/CheckLib.pm line 375.
Use of uninitialized value in -x at inc/Devel/CheckLib.pm line 376.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Use of uninitialized value $rest[0] in join or string at C:/Perl/lib/File/Spec/Win32.pm line 394.
Couldn't find your C compiler
Compilation failed in require at inc/Module/Install/CheckLib.pm line 17.
Warning: No success on command[C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site
]
RKITOVER/Net-SSH2-0.53.tar.gz
C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site -- NOT OK
1
2
3
4
5
6
7
8
9
10
11
12
13
my $chan = $SSH2 -> channel();
$chan -> blocking(0);
$chan -> shell();
print $chan "ls -la\n";
print "LINE : $_" while <$chan>;
print $chan "who\n";
print "LINE : $_" while <$chan>;
print $chan "date\n";
print "LINE : $_" while <$chan>;
1
2
3
4
5
LINE : Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-042stab108.7 x86_64)
LINE :
LINE : * Documentation: https://help.ubuntu.com/
LINE : root pts/0 Sep 21 18:28 (x590e0c57.dyn.telefonica.de)
LINE : Mon Sep 21 20:36:55 CEST 2015
Sep 20 22:20:38 meinserver sshd[798]: Connection closed by meinserver [preauth]
1
2
3
4
Sep 20 22:22:22 meinserver sshd[807]: Accepted publickey for root from 176.28.16.18 port 53320 ssh2: RSA 2f:1f:3d:ef:fe:73:c0:42:a8:8b:35:0f:3b:47:d2:3e
Sep 20 22:22:22 meinserver sshd[807]: pam_unix(sshd:session): session opened for user root by (uid=0)
Sep 20 22:22:22 meinserver sshd[807]: pam_env(sshd:session): Unable to open env file: /etc/default/locale: No such file or directory
Sep 20 22:22:25 meinserver sshd[807]: Received disconnect from 176.28.16.18: 11: disconnected by user