SSH.NET Public Key Authentication [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • SSH.NET Authenticate via private key only (public key authentication)

    3 answers




I know that private key authentication works, however I'm looking for public key authentication.



I'm trying to establish a connection using SSH.NET and a public key.



In the Git Bash terminal I can connect and run commands fine using my public key, but when I try connecting to the same host using SSH.NET I get an exception.



Here is my how I'm trying to connect:



using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}


I've also tried this route:



var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))


Both give the same exception: Permission denied (publickey).



It seems as though I need to specify where my public key is, or I need to put my public key in a certain spot, but I can't find any documentation telling me where to put it.










share|improve this question















marked as duplicate by Window, Community Dec 3 '18 at 22:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

    – Martin Prikryl
    Nov 17 '18 at 6:46













  • @MartinPrikryl Thanks for pointing that out.

    – Window
    Nov 19 '18 at 19:32






  • 1





    OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

    – Martin Prikryl
    Nov 21 '18 at 7:09




















0
















This question already has an answer here:




  • SSH.NET Authenticate via private key only (public key authentication)

    3 answers




I know that private key authentication works, however I'm looking for public key authentication.



I'm trying to establish a connection using SSH.NET and a public key.



In the Git Bash terminal I can connect and run commands fine using my public key, but when I try connecting to the same host using SSH.NET I get an exception.



Here is my how I'm trying to connect:



using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}


I've also tried this route:



var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))


Both give the same exception: Permission denied (publickey).



It seems as though I need to specify where my public key is, or I need to put my public key in a certain spot, but I can't find any documentation telling me where to put it.










share|improve this question















marked as duplicate by Window, Community Dec 3 '18 at 22:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

    – Martin Prikryl
    Nov 17 '18 at 6:46













  • @MartinPrikryl Thanks for pointing that out.

    – Window
    Nov 19 '18 at 19:32






  • 1





    OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

    – Martin Prikryl
    Nov 21 '18 at 7:09
















0












0








0


1







This question already has an answer here:




  • SSH.NET Authenticate via private key only (public key authentication)

    3 answers




I know that private key authentication works, however I'm looking for public key authentication.



I'm trying to establish a connection using SSH.NET and a public key.



In the Git Bash terminal I can connect and run commands fine using my public key, but when I try connecting to the same host using SSH.NET I get an exception.



Here is my how I'm trying to connect:



using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}


I've also tried this route:



var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))


Both give the same exception: Permission denied (publickey).



It seems as though I need to specify where my public key is, or I need to put my public key in a certain spot, but I can't find any documentation telling me where to put it.










share|improve this question

















This question already has an answer here:




  • SSH.NET Authenticate via private key only (public key authentication)

    3 answers




I know that private key authentication works, however I'm looking for public key authentication.



I'm trying to establish a connection using SSH.NET and a public key.



In the Git Bash terminal I can connect and run commands fine using my public key, but when I try connecting to the same host using SSH.NET I get an exception.



Here is my how I'm trying to connect:



using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}


I've also tried this route:



var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))


Both give the same exception: Permission denied (publickey).



It seems as though I need to specify where my public key is, or I need to put my public key in a certain spot, but I can't find any documentation telling me where to put it.





This question already has an answer here:




  • SSH.NET Authenticate via private key only (public key authentication)

    3 answers








c# ssh ssh.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 23:18







Window

















asked Nov 16 '18 at 19:46









WindowWindow

5801516




5801516




marked as duplicate by Window, Community Dec 3 '18 at 22:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Window, Community Dec 3 '18 at 22:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

    – Martin Prikryl
    Nov 17 '18 at 6:46













  • @MartinPrikryl Thanks for pointing that out.

    – Window
    Nov 19 '18 at 19:32






  • 1





    OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

    – Martin Prikryl
    Nov 21 '18 at 7:09





















  • The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

    – Martin Prikryl
    Nov 17 '18 at 6:46













  • @MartinPrikryl Thanks for pointing that out.

    – Window
    Nov 19 '18 at 19:32






  • 1





    OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

    – Martin Prikryl
    Nov 21 '18 at 7:09



















The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

– Martin Prikryl
Nov 17 '18 at 6:46







The first argument of PrivateKeyAuthenticationMethod is a username, not a key file path.

– Martin Prikryl
Nov 17 '18 at 6:46















@MartinPrikryl Thanks for pointing that out.

– Window
Nov 19 '18 at 19:32





@MartinPrikryl Thanks for pointing that out.

– Window
Nov 19 '18 at 19:32




1




1





OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

– Martin Prikryl
Nov 21 '18 at 7:09







OK, I've posted an answer, that's more or less a comment that explains why your question is actually a duplicate - it's just a terminology confusion. And it also explains why your answer is not really correct. It's not that "there is no way to use a public key to authenticate using SSH.NET." - It's actually that "there is no way to use a public key (only) to authenticate at all."

– Martin Prikryl
Nov 21 '18 at 7:09














1 Answer
1






active

oldest

votes


















0














There's no "private key authentication". It's actually called "public key authentication".



Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server - So the server authenticates you using the public key only. The private key is used locally only.



Though file formats that are commonly referred to as a private key (like PEM or .ppk) - as opposite to public key (.pub) formats - actually contain whole key pair (both public and private key).



So the question that you link to - SSH.NET Authenticate via private key only (public key authentication) - actually does what you want. It shows how to authenticate using "public key authentication" - using private key file format (both public and private key really). I've edited the title of that question to make this more clear.





And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" - That's not possible. You must have a private key too.






share|improve this answer





















  • 1





    Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

    – Window
    Nov 27 '18 at 19:35


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There's no "private key authentication". It's actually called "public key authentication".



Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server - So the server authenticates you using the public key only. The private key is used locally only.



Though file formats that are commonly referred to as a private key (like PEM or .ppk) - as opposite to public key (.pub) formats - actually contain whole key pair (both public and private key).



So the question that you link to - SSH.NET Authenticate via private key only (public key authentication) - actually does what you want. It shows how to authenticate using "public key authentication" - using private key file format (both public and private key really). I've edited the title of that question to make this more clear.





And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" - That's not possible. You must have a private key too.






share|improve this answer





















  • 1





    Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

    – Window
    Nov 27 '18 at 19:35
















0














There's no "private key authentication". It's actually called "public key authentication".



Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server - So the server authenticates you using the public key only. The private key is used locally only.



Though file formats that are commonly referred to as a private key (like PEM or .ppk) - as opposite to public key (.pub) formats - actually contain whole key pair (both public and private key).



So the question that you link to - SSH.NET Authenticate via private key only (public key authentication) - actually does what you want. It shows how to authenticate using "public key authentication" - using private key file format (both public and private key really). I've edited the title of that question to make this more clear.





And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" - That's not possible. You must have a private key too.






share|improve this answer





















  • 1





    Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

    – Window
    Nov 27 '18 at 19:35














0












0








0







There's no "private key authentication". It's actually called "public key authentication".



Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server - So the server authenticates you using the public key only. The private key is used locally only.



Though file formats that are commonly referred to as a private key (like PEM or .ppk) - as opposite to public key (.pub) formats - actually contain whole key pair (both public and private key).



So the question that you link to - SSH.NET Authenticate via private key only (public key authentication) - actually does what you want. It shows how to authenticate using "public key authentication" - using private key file format (both public and private key really). I've edited the title of that question to make this more clear.





And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" - That's not possible. You must have a private key too.






share|improve this answer















There's no "private key authentication". It's actually called "public key authentication".



Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server - So the server authenticates you using the public key only. The private key is used locally only.



Though file formats that are commonly referred to as a private key (like PEM or .ppk) - as opposite to public key (.pub) formats - actually contain whole key pair (both public and private key).



So the question that you link to - SSH.NET Authenticate via private key only (public key authentication) - actually does what you want. It shows how to authenticate using "public key authentication" - using private key file format (both public and private key really). I've edited the title of that question to make this more clear.





And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" - That's not possible. You must have a private key too.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 7:13

























answered Nov 21 '18 at 7:08









Martin PrikrylMartin Prikryl

92.1k22183388




92.1k22183388








  • 1





    Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

    – Window
    Nov 27 '18 at 19:35














  • 1





    Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

    – Window
    Nov 27 '18 at 19:35








1




1





Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

– Window
Nov 27 '18 at 19:35





Thank you for the clarification. I was under the assumption that the two were different because the answer stackoverflow.com/a/40974288/3103633 suggests that.

– Window
Nov 27 '18 at 19:35





Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python