App-SSH-SwitchShell
view release on metacpan or search on metacpan
pop @dirs;
$myhome = File::Spec->catdir(@dirs);
if ( exists $ENV{HOME} && defined $ENV{HOME} && -d $ENV{HOME} ) {
my $home = File::Spec->canonpath( $ENV{HOME} );
my $home_rp = Cwd::realpath($home);
my $myhome_rp = Cwd::realpath($myhome);
return if $home_rp eq $myhome_rp;
}
$ENV{HOME} = $myhome;
if ( !chdir $myhome ) {
print {*STDERR} "Could not chdir to home '$myhome': $ERRNO";
}
return;
}
sub get_abs_script_basedir {
my $basedir = File::Spec->rel2abs(__FILE__);
$basedir = ( File::Spec->splitpath($basedir) )[1];
$basedir = File::Spec->canonpath($basedir);
return $basedir;
}
sub configure_shell {
my $shell = get_shell();
# Make sure SHELL points to the correct shell, either the shell
# specified as argument, the shell from the password file, or /bin/sh
$ENV{SHELL} = $shell;
return $shell;
}
sub get_shell {
# The shell can be specified as argument
if (@ARGV) {
my $shell = shift @ARGV;
if ( !File::Spec->file_name_is_absolute($shell) ) {
print {*STDERR} "Shell '$shell' is not an absolute path\n";
}
elsif ( !-e $shell ) {
print {*STDERR} "Shell '$shell' does not exist\n";
}
else {
return $shell if -x $shell;
print {*STDERR} "Shell '$shell' is not executable\n";
}
}
# Get the shell from the password data. An empty shell field is
# legal, and means /bin/sh.
my $shell = ( getpwuid $EUID )[8];
return $shell if defined $shell && $shell ne q{};
return '/bin/sh';
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
sshss - Use your preferred shell and own home directory for shared SSH accounts
=head1 VERSION
Version 0.006
=head1 SYNOPSIS
=over
=item B<sshss> [shell]
=back
=head1 DESCRIPTION
B<sshss> adds support to ease the pain of these dreadful shared accounts
prevalent at some organizations. All you have to do is add B<sshss> to
the I<command> string of the F<authorized_keys> file. B<sshss> lets you
define a different shell then the one defined in the passwd database for the
shared account and lets you define a different directory as your home
directory. You are most likely going to use a subdirectory of the shared
accounts home directory.
Both features, the personal home directory and the shell change, can be used
independently without using the other.
If you specify a new shell the shell is not only used as the interactive
shell but also if you directly run a command. This includes commands that
run over SSH like L<scp(1)|scp(1)> and L<rsync(1)|rsync(1)>. It's your
responsibility to not use an overly obscure shell that breaks these commands.
The used shell must support the I<-c> flag to run a command, which is used if
you run a command directly over SSH, including L<scp(1)|scp(1)> and L<rsync(1)|rsync(1)>.
This is the default used by SSH itself. If your shell would work with plain
SSH, it should also work with B<sshss>.
B<sshss> tries to behave as much as possible like the C<do_child> function
from F<session.c> from OpenSSH portable.
B<sshss> uses no non-core modules.
=head1 OPTIONS
=over
( run in 2.719 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )