Reset Root Password of your Synology through PowerShell SSH (Without Putty)

Recently I had to reset my Root account password on my Synology DS214Play.
I had set the password when I first got the Synology, and of course I forgot it.

Resetting the account is no problem as there is a clear manual available on the Synology forums.
However I wanted to do this trough PowerShell.

One of the reasons I wanted to do this using PowerShell was because I was curious if it was possible to talk to Linux with PS.

First we need to connect to the device using SSH. For this we will need to load a module in PowerShell.

The module is called “Posh-SSH” and is supported from PowerShell 3.0 and up. First lets see if PowerShell can find it.

   1: Find-Module Posh-SSH


Now PowerShell found the module, lets install!

   1: Install-Module Posh-SSH


Now it has installed the module successfully, let’s see which commands are available.

   1: Get-Command -Module Posh-SSH


Seems that “New-SSHSession” is the command we need. Although that specific command isn’t listed there is a “Remove-SSHSession” so it should be available?

   1: Help New-SSHSession


Now according to the help, if we want to connect to a remote device we should use the following command:

   1: New-SSHSession -Computername "IP of your Synology" -Port "Port" -Credential (Get-Credential)



Ok, now we seem to have a active connection to our Synology trough SSH.
But we also want to run some commands on the device.

According to Posh-SSH we can run single commands using

   1: Invoke-SSHCommand -Index 0 -Command "Your command here"

But after running the command it will close that session. (The connection remains open)

And because we want to reset the Root account we need to be able to use “SUDO”. This is not possible using the command mentioned above because running “SUDO” will ask for credentials. And as the “Invoke-SSHCommand” will close the session after running the command, we can’t enter those.

Luckily they thought about this while building “Posh-SSH”

Specifically for when you want to run multiple command or need the session to stay open for other reasons there is “SSHStream”.
With this the session will stay open so we have more options.

To use the stream option we first have to define which stream we are referring to.

   1: $stream = New-SSHShellStream -Index 0

Now that we have defined the stream we can start throwing commands at it.

As we want to reset the Root account password we will need to run “synouser -setpw root Password”
But this command is required to be run under SUDO so it will be “SUDO synouser -setpw root Password”

As mentioned earlier, when running SUDO we need to provide a password. In Linux the reply would be:

   1: SUDO synouser -setpw root Password1

   2: Password:

The make sure the password request is also filled in we use “Invoke-SSHStreamExpectSecureAction”
The “ –ExpectString” corresponds with the reply the Terminal is giving.

   1: Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command 'sudo synouser -setpw root Password1' -ExpectString 'Password:' -SecureAction (read-host -AsSecureString) -Verbose

With this command the Root password will be reset to “ Password1”

If we want to know what the terminal is displaying (as it is not a live feed of the terminal) we can run “$stream.Read()”
This way we know what the terminal is replying.

After installing the Posh module the complete script to reset the Root password will be something like:

   1: New-SSHSession -ComputerName IpOfYourSynology -Port ** -Credential (Get-Credential)

   2: $stream = New-SSHShellStream -Index 0

   3: Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command 'sudo synouser -setpw root Password1' -ExpectString 'Password:' -SecureAction (read-host -AsSecureString) -Verbose

   4: $stream.Read()

Don’t use Password1 for your Root password but use something creative Winking smile

Also we are now using this module to reset a password, but we can also use it to run other command on Linux while using Powershell.

An experienced and creative IT specialist that proactively contributes to achieving customers’ goals. Is highly driven to finish a job within the agreed time-frame. Special roles: systems engineer, system manager, project co-worker, team leader, migration specialist.

Core qualities
Customer-focused, energetic, collegial, critical, driven

Snowboarding, wakeboarding, jiu-jitsu, mountain biking, travelling

Job description
Systems Engineer

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *