OpenSsh: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
Zeile 45: Zeile 45:


== Chroot für Login: ==
== Chroot für Login: ==
* /usr/local/bin/MkJail:
* /usr/local/bin/MkChroot.pl:
<pre>#! /bin/bash
<pre>cat <<'EOS' >/usr/local/bin/MkChroot.pl
function MkJail(){
#! /usr/bin/perl
local base=$1
use strict;
local publicdir=$2
 
local localdir=$3
my $gv_zip = "/tmp/chroot.zip";
if [ ! -d $base ] ; then
 
echo "not a directory: $base
my $prog = shift;
exit 1
my %gv_files;
fi
if ($prog eq ''){
if [! -d $publicdir ] ; then
die "usage: LbSrch.pl <program>";
echo "not a directory: $publicdir
exit 1
fi
for dir in bin proc lib lib64 usr ; do
mkdir -p /$base/$dir
mount -o bind /$dir $base/$dir
done
mkdir -p $base/$localdir
mount -o bind $publicdir $base/$localdir
}
}
case $1 in
if ($prog !~ m!/!){
ftpshop)
$prog = qx(which $prog);
MkJail /opt/jail_shop /srv/www/ueberkinger-shop.com shop
}
;;
&Init;
ftpsite)
&HandleLibs($prog);
MkJail /opt/jail_site /srv/www/ueberkinger.com www
exit 0;
;;
 
*)
sub HandleLibs{
echo "usage MkJail { ftpshop | ftpsite }"
my $prog = shift;
;;
my @lines = qx(ldd $prog);
esac
foreach my $line(@lines){
# => /lib/x86_64-linux-gnu/libdl.so.2
if ($line =~ m!^\s*(/\S+)!){
&Add($1);
} elsif ($line =~ m!=> (/\S+)!){
&Add($1);
} else {
print "ignored: $line";
}
}
}
sub Add {
my $file = shift;
if ($gv_files{$file} eq ''){
my $cmd = "zip -9 $gv_zip $file";
print $cmd, "\n";
system($cmd);
$gv_files{$file} = 1;
&HandleLibs($file);
}
}
sub Init{
foreach(qx(unzip -Z -1 $gv_zip)){
chomp;
$gv_files{"/$_"} = 1;
}
}
EOS
</pre>
</pre>
* Mount als /etc/fstab-Eintrag:
* Mount als /etc/fstab-Eintrag:
<pre>/usr  /opt/jail_site/usr none bind 0 0
<pre>/usr  /opt/jail_site/usr none bind 0 0
</pre>
</pre>

Version vom 26. August 2018, 22:56 Uhr


Konfiguration

Schlüsselgenerierung

 ssh-keygen -t rsa -b 4096

ssh-Sitzung mit Schlüssel

  • id_rsa.pub auf dem Zielrechner in die Datei authorized_keys eintragen
  • Verzeichnis ist das Homeverzeichnis des Users, mit dem angemeldet wird.
chmod 755 .ssh
chmod 600 .ssh/authorized_keys

Kommandos

ssh -i /home/jonny/id_rsa jonny@extern.host.de

rsync -e "ssh -i /home/jonny/id_rsa" /home backup@backup.example.com

SFTP-chroot-Umgebung

  • /etc/ssh/sshd_config
Match Group sftponly
        ChrootDirectory /home/%u
        ForceCommand internal-sftp
        AllowTcpForwarding no

oder

Match User jonny
        ChrootDirectory /opt/jail_jonny
        ForceCommand internal-sftp
        AllowTcpForwarding no
  • Rechte /opt/jail_jonny:
DIR=/opt/jail_jonny
chown root.root $DIR
chmod 755 $DIR
  • Eintrag in /etc/fstab:
/data/dir1   /opt_jail_jonny     none    bind   

Chroot für Login:

  • /usr/local/bin/MkChroot.pl:
cat <<'EOS' >/usr/local/bin/MkChroot.pl
#! /usr/bin/perl
use strict;

my $gv_zip = "/tmp/chroot.zip";

my $prog = shift;
my %gv_files;
if ($prog eq ''){
	die "usage: LbSrch.pl <program>";
}
if ($prog !~ m!/!){
	$prog = qx(which $prog);
}
&Init;
&HandleLibs($prog);
exit 0;

sub HandleLibs{
	my $prog = shift;
	my @lines = qx(ldd $prog);
	foreach my $line(@lines){
		# => /lib/x86_64-linux-gnu/libdl.so.2
		if ($line =~ m!^\s*(/\S+)!){ 
			&Add($1);
		} elsif ($line =~ m!=> (/\S+)!){
			&Add($1);
		} else {
			print "ignored: $line";
		}
	}
}
sub Add {
	my $file = shift;
	if ($gv_files{$file} eq ''){
		my $cmd = "zip -9 $gv_zip $file";
		print $cmd, "\n";
		system($cmd);
		$gv_files{$file} = 1;
		&HandleLibs($file);
	}
}
sub Init{
	foreach(qx(unzip -Z -1 $gv_zip)){
		chomp;
		$gv_files{"/$_"} = 1;
	}
}
EOS	
  • Mount als /etc/fstab-Eintrag:
/usr   /opt/jail_site/usr none bind 0 0