Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: PrivateKeyAuthentication from Stream

$
0
0
Hey all,

Situation:
  1. Want to connect from C# app to UNIX server using RSA PrivateKey (stored on local c: drive)with no passphrase. (works)
  2. Now I'd like to store the PrivateKey on another UNIX machine and be able to Stream / Read it in to be used by the same C# app. The reason is that i have the C# app installed on several machines, and I'd like to have them all be able to access the PrivateKey. This is especially true, since I will be changing my key every 90 days roughly. This will eliminate the need of distributing the PrivateKey too all the Windows machines everytime it changes. Can I pass in a 'path' to a URL or should I read the file using a System.Windows.Forms.WebBrowser?
So I noticed that the PrivateKeyFile class has 4 ways to use the overloaded method, the one that caught my attention: 'System.IO.Stream PrivateKey' seems like it would be what I'm going to do.

Is this the right method for what I'm trying to do? Something like: (psuedo)
private void button1_Click(object sender, EventArgs e)       
 {
            try
            {
                //CREDENTIALS
                //Works
    //string path = "C:\\Users\\Joe\\Documents\\DAR\\Keys\\joes_pk";

                //new path to web server with PK
                string path = "https://10.1.1.45/pk.php?pk=joes_pk";
                string unix_hostname = "10.1.1.10";
                int port = 22;
                string username = "unix_username";


                //Objects INIT
                PrivateKeyFile privatekey = new PrivateKeyFile(path);
                SshClient client = new SshClient(hostname, port, username, privatekey);
                client.Connect();

                //RUN command
                if (client.IsConnected)
                {
                    string cmd = "ls -la";
                    MessageBox.Show("Conected! Running " + cmd);
                    var output = client.RunCommand(cmd);
                    MessageBox.Show(output.Result.ToString() + " Will disconnect now...");
                    client.Disconnect();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error on makeConnection:" + exc.Message.ToString() + ":" + exc.StackTrace.ToString());
            }
        }
Let me know what ideas yall have on the best way to make a centralized PrivateKey that I can use with SSH.NET, thanks!

SK

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>