-
Notifications
You must be signed in to change notification settings - Fork 224
Description
The device in question is an UPS. Upon initial ssh connection it comes up with
You must change your password now and login again!
Changing password for local\admin
Old password:
Now with an actual ssh session I can enter "admin", since this is the default password, hit "enter" and then I can or could set the new password.
However with Posh-SSH 3.2.4, on Server 2022 Powershell 5.1 in Powershel_ISE, it does not work. Since it is needed over a large number of devices Posh-SSH is my first choice here since it worked well on a different project. However I always get "Incorrect password"
The actual commands are:
$SshSession = New-SSHSession -ComputerName $SSHTarget -Credential $Credential -AcceptKey -Verbose -ErrorAction Stop
$SSHStream = New-SSHShellStream -SSHSession $SshSession
Start-Sleep 2
$SSHStream.Read()
The console answers with:
Credentials are expired
Min password length: 8
Max password length: 32
Min uppercase characters: 1
Min lowercase characters: 1
Min digits: 1
Min special characters: 1
Valid special characters: `~!@#$%^&*()_-+={}[]|:;\"<>,.'?/
Last login: Mon Aug 11 11:41:32 2025 from 169.254.5.76
WARNING: Your password has expired.
You must change your password now and login again!
passwd: no record of local\admin in /etc/shadow, using /etc/passwd
Changing password for local\admin
Old password:
I then use:
$SSHStream.WriteLine("admin")
And the result is:
$SSHStream.read()
Incorrect password
passwd: password for local\admin is unchanged
Variation I tried:
$SSHStream.Write("admin`n")
, same result.
I also tried $SshSession.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::ASCII and $SSHStream.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::ASCII before even reading the opened stream.
Checking the encoding before and after shows it is applied:
PS:>$SshSession.Session.ConnectionInfo.Encoding
BodyName : utf-8
EncodingName : Unicode (UTF-8)
HeaderName : utf-8
WebName : utf-8
WindowsCodePage : 1200
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
IsSingleByte : False
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 65001
PS:>$SshSession.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::ASCII
PS:>$SshSession.Session.ConnectionInfo.Encoding
IsSingleByte : True
BodyName : us-ascii
EncodingName : US-ASCII
HeaderName : us-ascii
WebName : us-ascii
WindowsCodePage : 1252
IsBrowserDisplay : False
IsBrowserSave : False
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 20127
PS:>$SSHStream.Session.ConnectionInfo.Encoding
BodyName : utf-8
EncodingName : Unicode (UTF-8)
HeaderName : utf-8
WebName : utf-8
WindowsCodePage : 1200
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
IsSingleByte : False
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 65001
PS:>$SSHStream.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::ASCII
PS:>$SSHStream.Session.ConnectionInfo.Encoding
IsSingleByte : True
BodyName : us-ascii
EncodingName : US-ASCII
HeaderName : us-ascii
WebName : us-ascii
WindowsCodePage : 1252
IsBrowserDisplay : False
IsBrowserSave : False
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 20127
After all my attempts I tried several time with a normal ssh client, and the old password is still "admin", which I can enter.
Now am I doing something terribly wrong or is this a Posh-SSH thing?