Can't connect to my pc via ssh #2229
-
This is going to seem a little twisted, but for a lesson, I'm trying to connect via ssh to my own windows 11 pc. The goal is just to understand the principle of public or private ssh keys. To do that, i installed openssh using This tutorial and This tutorial: PS D:\Bureau\ssh-test> Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Name : OpenSSH.Client~~~~0.0.1.0 State : Installed Name : OpenSSH.Server~~~~0.0.1.0 State : NotPresent
PS D:\Bureau\ssh-test> Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Path :
Online : True
RestartNeeded : False
PS D:\Bureau\ssh-test> Start-Service sshd
PS D:\Bureau\ssh-test> Set-Service -Name sshd -StartupType 'Automatic'
PS D:\Bureau\ssh-test> if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
>> Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
>> New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
>> } else {
>> Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
>> }
Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists.
PS D:\Bureau\ssh-test> Get-Service -Name sshd | Set-Service -StartupType Automatic
PS D:\Bureau\ssh-test> Start-Service sshd
PS D:\Bureau\ssh-test> ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\User/.ssh/id_ed25519): test
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in test
Your public key has been saved in test.pub
The key fingerprint is:
SHA256:+VdBEwsH5up6wAyHsdjpY/GgD1Oci6m/w5X8ETTzsFs user@User
The key's randomart image is:
+--[ED25519 256]--+
....
+----[SHA256]-----+
PS D:\Bureau\ssh-test> dir
Répertoire : D:\Bureau\ssh-test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28/04/2024 20:16 411 test
-a---- 28/04/2024 20:16 100 test.pub
PS D:\Bureau\ssh-test> cat .\test
-----BEGIN OPENSSH PRIVATE KEY-----
<redacted>
-----END OPENSSH PRIVATE KEY-----
PS D:\Bureau\ssh-test> Add-Content -Path $env:USERPROFILE\\.ssh\\authorized_keys -Value "-----BEGIN OPENSSH PRIVATE KEY-----<redacted>-----END OPENSSH PRIVATE KEY-----"
PS D:\Bureau\ssh-test> Get-Service ssh-agent | Set-Service -StartupType Automatic
PS D:\Bureau\ssh-test> Start-Service ssh-agent
PS D:\Bureau\ssh-test> Get-Service ssh-agent
Status Name DisplayName
------ ---- -----------
Running ssh-agent OpenSSH Authentication Agent
PS D:\Bureau\ssh-test> ssh-add .\test
Identity added: .\test (user@User)
PS D:\Bureau\ssh-test> $authorizedKey = Get-Content -Path .\test.pub
PS D:\Bureau\ssh-test> $remotePowershell = "powershell New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh; Add-Content -Force -Path $env:USERPROFILE\.ssh\authorized_keys -Value '$authorizedKey'"
PS D:\Bureau\ssh-test> (Test-Connection -ComputerName (hostname) -Count 1).IPv4Address.IPAddressToString
10.188.34.26
PS D:\Bureau\ssh-test> ssh 10.100.10.26 $remotePowershell
user@10.100.10.26's password:
PS D:\Bureau\ssh-test> So i wanted to try to test my ip address on a server i have: server@Server:~ $ ping google.com
PING google.com(par21s19-in-x0e.1e100.net (2a00:1450:4007:813::200e)) 56 data bytes
64 bytes from par21s19-in-x0e.1e100.net (2a00:1450:4007:813::200e): icmp_seq=1 ttl=112 time=15.8 ms
64 bytes from par21s19-in-x0e.1e100.net (2a00:1450:4007:813::200e): icmp_seq=2 ttl=112 time=16.1 ms
64 bytes from par21s19-in-x0e.1e100.net (2a00:1450:4007:813::200e): icmp_seq=3 ttl=112 time=16.2 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 15.787/16.039/16.216/0.182 ms
server@Server:~ $ ping 10.100.10.26
PING 10.100.10.26 (10.100.10.26) 56(84) bytes of data.
^C
--- 10.100.10.26 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 5111ms It keep asking me for my password, but i don't want to use it, i only want to use ssh-key to log. Can someone help me understant why it happend? And of course all the key value are false, but either way i removed the key |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I didn't see that you had already changed the key values, so I removed them from the post. If you are trying to connect as an account that is an administrator, the public key should be added to Also - no need to change the ssh command, but when connecting to the local machine, ssh will also recognize If that doesn't work, please provide the ssh client/server logs as described in https://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting-Steps |
Beta Was this translation helpful? Give feedback.
I didn't see that you had already changed the key values, so I removed them from the post.
If you are trying to connect as an account that is an administrator, the public key should be added to
$env:PROGRAMDATA\\administrators_authorized_keys
instead of$env:USERPROFILE\\.ssh\\authorized_keys
Also - no need to change the ssh command, but when connecting to the local machine, ssh will also recognize
localhost
in addition to the ip address.If that doesn't work, please provide the ssh client/server logs as described in https://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting-Steps