mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
9e1ee0a380
* Bump alpine from 3.20 to 3.21 in /test/Renci.SshNet.IntegrationTests Bumps alpine from 3.20 to 3.21. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * merge #1553 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
namespace Renci.SshNet.IntegrationTests
|
|
{
|
|
internal class SshConnectionDisruptor
|
|
{
|
|
private readonly IConnectionInfoFactory _connectionInfoFactory;
|
|
|
|
public SshConnectionDisruptor(IConnectionInfoFactory connectionInfoFactory)
|
|
{
|
|
_connectionInfoFactory = connectionInfoFactory;
|
|
}
|
|
|
|
public SshConnectionRestorer BreakConnections()
|
|
{
|
|
var client = new SshClient(_connectionInfoFactory.Create());
|
|
|
|
client.Connect();
|
|
|
|
PauseSshd(client);
|
|
|
|
return new SshConnectionRestorer(client);
|
|
}
|
|
|
|
private static void PauseSshd(SshClient client)
|
|
{
|
|
using (var command = client.CreateCommand("sudo echo 'DenyUsers sshnet' >> /etc/ssh/sshd_config"))
|
|
{
|
|
var output = command.Execute();
|
|
if (command.ExitStatus != 0)
|
|
{
|
|
throw new ApplicationException(
|
|
$"Blocking user sshnet failed with exit code {command.ExitStatus}.\r\n{output}\r\n{command.Error}");
|
|
}
|
|
}
|
|
|
|
using (var command = client.CreateCommand("sudo pkill -9 -U sshnet -f sshd-session.pam"))
|
|
{
|
|
var output = command.Execute();
|
|
if (command.ExitStatus != 0)
|
|
{
|
|
throw new ApplicationException(
|
|
$"Killing sshd-session.pam service failed with exit code {command.ExitStatus}.\r\n{output}\r\n{command.Error}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|