c # Conexão ao servidor usando serviços CLI e mono, permissões negadas

1

Estou desenvolvendo um aplicativo que fornece um diagnóstico em tempo real dos meus servidores em funcionamento e dos serviços que estou usando nesses servidores.

Primeiro de tudo, criei um aplicativo C # em um servidor remoto individual que pinga o outro endereço de servidor e retorna o resultado em um email, se o servidor remoto estiver inativo.

Gostaria, em seguida, de ver se um determinado serviço está sendo executado no mesmo endereço de servidor (systemctl status [servicename], para isso, criei chaves RSA e conectei-me ao servidor com esta chave, conforme mencionado aqui: link

Aqui está a função que eu uso para conectar ao meu servidor via ssh:

internal static void Command(string command, string arguments, string input = null)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.EnableRaisingEvents = false;
    process.StartInfo.FileName = command;
    process.StartInfo.RedirectStandardInput = input != null;
    process.StartInfo.UseShellExecute = input == null;
    process.Start();
    if (input != null)
    {
        process.StandardInput.WriteLine(input);
        process.StandardInput.Close();
    }
    process.WaitForExit();
    process.Close();
}

e meu código principal:

static void Main(string[] args)
{
    string[] Hardware = { "ELog", "SIY", "API" };
    while (true)
    {
        string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..");
        string crypto = Tools.GetString("ELog");
        foreach(string hard in Hardware)
        {
            crypto = Crypto.Decrypt(Tools.GetString(hard));
            PingReply reply = Pinger.PingHost(crypto);
            try
            {
                if (reply != null && ((reply.RoundtripTime > 200) || (reply.Status.ToString() != "Success") || (reply.Options.Ttl < 1)))
                {
                    Console.WriteLine("Diag Server NOK" + " Addresse : " + reply.Address.ToString() + " Status : " + reply.Status.ToString()
                        + " RoundTripTime : " + reply.RoundtripTime + " TTL : " + reply.Options.Ttl + " Buffer size : " + reply.Buffer.Length);
                    Tools.SendMail("mailaddress", "mailaddress2", "MySubject", " Addresse : " + reply.Address.ToString() + " Status : " + reply.Status.ToString()
                        + " RoundTripTime : " + reply.RoundtripTime + " TTL : " + reply.Options.Ttl + " Buffer size : " + reply.Buffer.Length);
                }
                else
                {
                    Console.WriteLine("Diag Server OK" + " Addresse : " + reply.Address.ToString() + " Status : " + reply.Status.ToString()
                        + " RoundTripTime : " + reply.RoundtripTime + " TTL : " + reply.Options.Ttl + " Buffer size : " + reply.Buffer.Length);
                }
            }
            catch(Exception e)
            {
                Tools.Exception(e);
            }
        }
        try
        {
            Linux.Command("ssh", "-i mykeyfilepath root@myserver systemctl status myservice");
        }
        catch(Exception e)
        {
            Tools.Exception(e);
        }
        Thread.Sleep(60000);
    }
}

'

Este programa funciona bem se eu chamá-lo com a seguinte linha no Oracle VM:

mono Pinger.exe

Diag Server OK Addresse : hidden Status : Success RoundTripTime : 65 TTL : 128 Buffer size : 0
Diag Server OK Addresse : hidden  Status : Success RoundTripTime : 30 TTL : 128 Buffer size : 0
Diag Server OK Addresse : hidden  Status : Success RoundTripTime : 30 TTL : 128 Buffer size : 0
● service.service - Comanche Web Development Server
   Loaded: loaded (servicepath; enabled)
   Active: active (running) since Wed 2018-05-23 17:17:13 CEST; 1 day 18h ago
 Main PID: 12368 (cli)
   CGroup: ...

mas quando eu chamo o aplicativo c # em um serviço Unix, eu recebo o erro de permissões ....

    systemctl start hello
    systemctl status hello
    ● hello.service - FTP update
       Loaded: loaded (/etc/systemd/system/hello.service; disabled; vendor preset: enabled)
       Active: active (running) since Fri 2018-05-25 11:29:04 CEST; 6s ago
     Main PID: 4038 (cli)
        Tasks: 3 (limit: 1113)
       CGroup: /system.slice/hello.service
               └─4038 /usr/bin/cli /Pinger.exe
    mai 25 11:29:04 nicolas-VirtualBox systemd[1]: Started FTP update.
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: Diag Server OK Addresse : hidden 2 Status : Success RoundTripTime : 25 TTL : 128 Buffer size : 0
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: Diag Server OK Addresse : hidden  Status : Success RoundTripTime : 23 TTL : 128 Buffer size : 0
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: Diag Server OK Addresse : hidden Status : Success RoundTripTime : 27 TTL : 128 Buffer size : 0
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: Permission denied, please try again.
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: Permission denied, please try again.
    mai 25 11:29:05 nicolas-VirtualBox Pinger.exe[4038]: root@serveraddress: Permission denied (publickey,password).

Deve ser um erro de permissão, quando eu criei os arquivos de chave, eu os protegi com uma frase-senha, poderia ser isso?

Estou tentando recriar o arquivo-chave sem frase-senha e postar o resultado quando terminar.

EDIT 1 Eu tentei gerar outra chave sem uma frase secreta, mesmo resultado .... Eu também mudei a permissão dos arquivos keygen é legível por todos (apenas para tentar depois que deve ser legível apenas por mim), Pinger.exe é executável por todos e chave pública no servidor também é legível.

Quaisquer pensamentos seriam apreciados

    
por Marech 25.05.2018 / 15:02

0 respostas