The $ in /(^\s*AcceptEnv.*$)/ matches before the newline, so $1 did not contain it and the following line was appended to the comment - which commented out the Subsystem sftp line on a stock Debian sshd_config. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
25 lines
351 B
Perl
Executable File
25 lines
351 B
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
$SSHCONF='/etc/ssh/sshd_config';
|
|
|
|
$out="";
|
|
open(IN,$SSHCONF);
|
|
while(<IN>) {
|
|
|
|
if (/^\s*\#*\s*PermitRootLogin/) {
|
|
$out.="PermitRootLogin yes\n" ;
|
|
} elsif (/(^\s*AcceptEnv.*$)/) {
|
|
$out.="#$1\n";
|
|
} else {
|
|
$out.=$_;
|
|
}
|
|
}
|
|
close(IN);
|
|
|
|
open(OUT,"> $SSHCONF");
|
|
print OUT $out;
|
|
close(OUT);
|
|
|
|
system("service ssh restart");
|
|
|