PowerShell SSH lets you access and manage remote systems from virtually anywhere. SSH also offers detailed logging functions that allow complete monitoring and tracking of activities on your server. Our step-by-step guide tells you everything about Powershell SSH!
PowerShell SSH Requirements
SSH integration in Windows PowerShell gives you the ability to establish SSH connections to remote systems and run commands SSH in a PowerShell script. This makes it easier to manage and automate tasks in distributed computing infrastructures, especially in a heterogeneous environment that includes both Windows and non-Windows systems.
To use PowerShell SSH, you must meet the following requirements:
- Installing PowerShell : Make sure you have PowerShell v6+ installed on your local computer. PowerShell usually comes pre-installed on Windows, but the installed version must support SSH.
- SSH Client : You need an SSH client in your PowerShell environment to establish SSH connections. On Windows 10/11 and Windows Server 2019, OpenSSH is available by default. If you are using an earlier version of Windows, you may need to install OpenSSH manually.
- SSH Server : The SSH server is the target server to connect to. This can be a Linux server, a network device, or another SSH-enabled host.
- Network access : Your local computer must have network access and be able to reach the remote SSH server. Port 22 must be opened for SSH in the firewall rules.
- PowerShell Modules : There are PowerShell modules specifically designed for using SSH, such as the “PSSession” or “Posh-SSH” module. You need to make sure that the corresponding module is installed on your system in order to use SSH in PowerShell.
- Permissions : You must have administrator or extended privileges and an SSH password or key to be able to establish SSH connections from your local computer and access the remote server.
Dedicated Servers with IONOS
At the crossroads of hardware and the Cloud: dedicated servers with Cloud integration and billing by the minute + personal advisor!
24/7 Support
Unlimited traffic
SSL Certificate
Before you can use Secure Shell (SSH) in PowerShell, you must configure the server OpenSSH. You can then start the PowerShell SSH session and run commands on the remote system.
Step 1: Install OpenSSH
Click on the “Start” menu or type “PowerShell” in the search bar. Select Run as administrator to open Windows PowerShell. The following PowerShell command allows you to install the OpenSSH feature on your Windows computer:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
powershell
Step 2: Start the OpenSSH service
Once the installation is complete, you can start the OpenSSH service:
Start-Service sshd
powershell
You can check if the OpenSSH service is running with the following command:
Get-Service sshd
powershell
The statute Running indicates that sshd is running correctly.
Step 3: Automatically start the SSH server service
To enable the OpenSSH server service every time Windows restartsyou can enter the following command:
Set-Service -Name sshd -StartupType 'Automatic'
powershell
Step 4: Customize the firewall
If Windows Firewall is active, you need to add a rule to allow SSH traffic on port 22 (the default SSH port).
New-NetFirewallRule -Name 'OpenSSH-Server' -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
powershell
Step 5: Establish SSH connection
You can now connect to your SSH server from another device. To do this, open PowerShell on your client PC and enter the SSH command with the username and server address.
ssh username@servername
powershell
Replace “username” with your SSH username and “servername” with the IP address or hostname of the remote server. When you run the command, you will be prompted for your SSH password, unless you are using SSH keys for authentication.
Step 6: Working in the SSH session
Once you have established an SSH connection, you can run commands on the remote server as if you were physically connected to the server. To end the SSH session and return to local PowerShell, you can use the command exit
.
There are a number of SSH commands in PowerShell. The command pwd
(print working directory) indicates for example the current working directory:
Here is a list of commands you can use in PowerShell SSH:
-
ls/dir
: display the contents of a directory -
cd
: change directory on the remote server -
touch/New-Item
: create a new file -
rm/Remove-Item
: Delete files or directories -
mv/Move-Item
: move or rename files and directories -
useradd
: add a user -
scp
: transfer files between client and server
You can find more commands in our PowerShell commands overview.