Can edit authorized_keys in SSH Services, remove download keyfile support

This commit is contained in:
nicolas.dorier
2019-09-19 19:17:20 +09:00
parent 42dda56eea
commit a2cb6178b8
6 changed files with 83 additions and 16 deletions

View File

@@ -49,13 +49,18 @@ namespace BTCPayServer
return tcs.Task;
}
public static string EscapeSingleQuotes(this string command)
{
return command.Replace("'", "'\"'\"'", StringComparison.OrdinalIgnoreCase);
}
public static Task<SSHCommandResult> RunBash(this SshClient sshClient, string command, TimeSpan? timeout = null)
{
if (sshClient == null)
throw new ArgumentNullException(nameof(sshClient));
if (command == null)
throw new ArgumentNullException(nameof(command));
command = $"sudo bash -c '{command}'";
command = $"bash -c '{command.EscapeSingleQuotes()}'";
var sshCommand = sshClient.CreateCommand(command);
if (timeout is TimeSpan v)
sshCommand.CommandTimeout = v;