authorized_keys
file (server)
with command restricted to the service application
$ ./time-client.pl 17:25:3
$ cat -n time-client.pl 1 #!/usr/bin/env perl 2 use lib '../lib'; 3 use warnings; 4 use strict; 5 use SSH::RPC::Client; 6 use Getopt::Long; 7 8 my ($host, $hires); 9 10 $host = 'sshrpc'; 11 my $ssh = SSH::RPC::Client->new($host); 12 my $command = ($hires) ? "hiResTime" : "time"; 13 my $result = $ssh->run($command); 14 if ($result->isSuccess) { 15 if ($hires) { 16 printf "%02d:%02d:%02d.%d\n", @{$result->getResponse}; 17 } 18 else { 19 print $result->getResponse."\n"; 20 } 21 } 22 else { 23 die $result->getError; 24 }
$ cat -n time-shell.pl 1 #!/usr/bin/perl 2 3 use strict; 4 use TimeShell; 5 6 TimeShell->run();El Módulo cargado por el servidor:
$ cat -n TimeShell.pm 1 package TimeShell; 2 3 use lib '../lib'; 4 use strict; 5 use base 'SSH::RPC::Shell'; 6 use Time::HiRes; 7 8 sub run_time { 9 my @time = localtime(time()); 10 return { 11 status => 200, 12 response => join(":", $time[2], $time[1], $time[0]), 13 }; 14 } 15 16 sub run_hiResTime { 17 my ($seconds, $microseconds) = Time::HiRes::gettimeofday(); 18 my @time = localtime($seconds); 19 return { 20 status => 200, 21 response => [ $time[2], $time[1], $time[0], $microseconds ], 22 }; 23 } 24 25 1;
Comando forzado:
pp2@nereida:~/Lbook$ cat /home/pp2/.ssh/authorized_keys ssh-dss ... ... command="/home/pp2/Lperltesting/SSHRPC/examples/time-shell.pl" ssh-dss AAAA...= casiano@MacBookdeCasiano.local