C# Connection to server using CLI services and mono, permissions denied


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C# Connection to server using CLI services and mono, permissions denied
# 1  
Old 05-25-2018
C# Connection to server using CLI services and mono, permissions denied

I am developping an application that give a real time diagnosis of my working servers and of the services I am using on these server.

First of all I created a C# application on an individual remote server that pings the another server adress and gives back the result in an email if remote server is down.

I would like then to see if a certain service is running on the same server address(systemctl status [servicename], for this purpose, I created RSA keys and connect to the server with this key as mentionned here : https://hostpresto.com/community/tutorials/how-to-connect-to-a-linux-server-using-secure-shell-ssh/

Here is the function I use to connect to my server via ssh :

Code:
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();
    }

and my main code :

Code:
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);
        }
    }

This program works fine if I call it with the following line in VM Oracle :

Code:
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: ...

but when I call the c# application in a service Unix, I get permissions error....

Code:
 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).

It should be a permission error, when i created the keyfiles, i protected them with a passphrase could it be that ?

I am trying to recreate keyfile without passphrase and post the result when it's done.

**EDIT 1**
I tryied to generate another key without a passphrase, same result....
I also changed the permission of the files keygen is readable by everyone (just to try after it should be readable only by me), Pinger.exe is executable by everyone and public key in server is also readable.

Any thoughts would be appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

X-Server access is denied on host

The situation is: I have a RHEL 7.3 VM that I am able to access via both ssh and VM console. I am able to run all of the standard commands for verifying that X11 forwarding/xhost permissions are working (xclock, nautilus, firefox, etc.) i can also run the runInstaller for Oracle client, No problems... (1 Reply)
Discussion started by: melghaze
1 Replies

2. SuSE

Fetch port services from LDAP server

Hi, We have a ldap server configured with services (port) and want to know how to fetch that to the ldap clients: # cat /etc/nsswitch.conf|grep -i services services: files sss (neither sss nor ldap works) by doing "#getent services" I am getting only the result from /etc/services but I... (1 Reply)
Discussion started by: Sridaran
1 Replies

3. Solaris

Cannot login to SMB Server/Authentication denied

Hello, I have problems seting up SMB server in Solaris 11.3. I had SMB working previously on Solaris 11 (updated to 11.3), but a bad harddisk crash forced me to install Solaris again from scratch and I cannot get it working properly. I have imported the previous zfs pool with share.smb set... (7 Replies)
Discussion started by: Zorken
7 Replies

4. Linux

Application services not starting with server reboot

Hi All, My application uses three different sub-services to make complete application up and running to normal. The entry of all the three services are present in /etc/init.d directory with proper softlink created to application home path where it actually exists. In one rare case one of the... (3 Replies)
Discussion started by: hk_kamozalwar
3 Replies

5. AIX

SSH connection "Permission denied"

Hello, I tried to connect with root or any other user to AIX using ssh. It throws me error like Permission denied (publickey,keyboard-interactive). i don't know why!! and the PermitRootLogin is yes any help will be appreciated Thanks (7 Replies)
Discussion started by: moudmm
7 Replies

6. Shell Programming and Scripting

proxy server with wget or cli curl

I'm using a proxy service with an ip address and a port number. How do I use the proxy with wget or cli curl? (1 Reply)
Discussion started by: locoroco
1 Replies

7. Solaris

SMTP server-denied

im running Solaris9. sendmail version 8.13 every now and then my smtp server is being blacklisted resulting to relay denied to some of my client. what is the very first thing i have to implement? thanks (1 Reply)
Discussion started by: uwagon
1 Replies

8. HP-UX

The server is not starting all services

Hi everybody When I Boot/restart my HP-UX server when it reaches the step described below doesn't go through. When I kick a key in the console it show me the login prompt and a can log on but I cannot access the server from the network, I can only do it via LAN console. Please, can you help... (3 Replies)
Discussion started by: cgege
3 Replies

9. UNIX for Advanced & Expert Users

mount: failed, reason given by server: Permission denied

Hi , I have a filesystem on AIX 4.3.3 which i need to share with other clients who use Windows NT and Redhat linux 7.3. I use samba to share this with Windows NT Clients. Now i was to share this with Linux clients. When i try to nfs mount this on Linux i get "mount: failed, reason given by... (1 Reply)
Discussion started by: Sushesh
1 Replies
Login or Register to Ask a Question