Re: [Ssh-sftp-perl-users] Net::SSH::perl to chroot enviro
Brought to you by:
dbrobins
|
From: John F. <joh...@zn...> - 2004-06-04 00:48:13
|
FYI
Answer-
How to use Net::SSH::Perl to run chrooted commands on remote server.
Rules:
1) you have to login as root, not the user
2) with each command you must run chroot as part of the command <see
example> to get a command running inside the chroot enviro
3) you must use absolute pathnames, even for well-known commands
4) you still have to be careful about the environment and shell - it
doesn't act like a normal bash shell you reach manually
Code snippet:
use strict;
use diagnostics;
use Net::SSH::Perl;
my $cmd = "/usr/sbin/chroot /home/username/buildenv/potato myscript
param param param" ;
# myscript runs with the potato directory as its root
my $ssh = Net::SSH::Perl->new($host, debug => 10, protocol => 2);
# using code from instructions...
$ssh->login($user, $pass);
my($out, $err, $exit) = $ssh->cmd($cmd);
print("\n " . $out1 ) if $out1;
Why would anyone want to do this?
I build multiple large images on a remote Linux server nightly. I wrote
a script to extract them from cvs, and build in a special build
environment. ( the server runs a different Linux from the builds)
I version control the build environment itself, so that various releases
are tied to a controlled version of Linux. Each developer and I get to
choose which environment we build in, depending on which release we are
working on, latest or bug fixes. Sometimes I have to tarball the whole
build enviro and give it to a customer, too. We used to keep removable
hard drives for each flavor, but now we use multiple chroot environments
on a bigger server.
thanks
John
----------------------------------------------------
John P. Fisher
at ZNYX Networks
805 683 1488 x 3245
joh...@zn...
|