These Posh-SSH examples pave the way to Linux management – TechTarget

5 min read

Although PowerShell is currently a cross-platform application that works across Windows, Linux and Mac platforms, the tool for managing is still in need of a hand to function across the various operating systems.

There are more Linux tasks are taking on the majority of infrastructure tasks traditionally handled in Windows Server, such as Active Directory domain controllers. The management tools that are available in Windows generally are limited to that purpose, and the range of tools available could not work with Linux. There is a simple way to use PowerShell to access details about Window Server systems, but even with PowerShell’s multi-platform capabilities it has been a challenge for Linux servers. Instead of having to master Bash programming, admins could utilize their PowerShell abilities to create code to obtain details about Linux systems. An PowerShell module dubbed Posh-SSH can help in bridging this gap by utilizing a collection of commands that provide extra functionality for use Linux operating systems.

Install the Posh-SSH Module

In order to begin, install the module on Linux using this command using administrator rights:

Install-Module -Name Posh-SSH

Based on the configuration and settings of the workstation, this command to modify the execution policies could be needed if the commands are not generating according to the expected output:

Set-ExecutionPolicy – RemoteSigned -Force Verbose

The Posh-SSH program includes a variety of capabilities that will be well-known for Linux administrators, for example the capability to send commands using the Secure Shell (SSH) session. To find a comprehensive listing of Posh-SSH commands, follow these commands in PowerShell:

Get-Command -Module Posh-SSH

To execute commands on the Linux server using Posh-SSH administrators must do two steps first connect to an SSH-enabled Linux server, and then run the necessary Posh-SSH software.

Following that, the command Invoke-SSHCommand returns the output of the command in the form of a variable. Administrators can use this as a method to collect information on the contents of files as well as running processes.

In order to use these capabilities, OpenSSH must be running on the server that you want to use. Check this with PuTTY or similar tools to connect via the port 22.

Make connections to the Linux machine

In the beginning, create the session using an Linux VM with OpenSSH installed. The basic form of this command reads as follows:

$setsession = New-SSHSession

The administrator is then required to complete a number of areas. If it’s time to automate the process, scripts can add the required property. Replace for the computername as well as the the Get-Credential username in accordance with your configuration requirements:

$setsession = New-SSHSession -ComputerName "192.168.83.128" -Credential (Get-Credential sysadmin)

First time the command is connected with the Linux server, it asks to acknowledge the fingerprint of the host. Enter “Y”to accept the fingerprint.



Connect to the Linux session via Windows PowerShell.

A different option is to utilize SSH keys, which can be delivered as a private file. This Find-Help-New-SSHSession command lists the possible options.

This tutorial employs this tutorial with the the Get-Credential function in the interest of simpleness. For the purpose of defining credentials within scripts, you must change with the Get-Credential part.

Ask questions about the system

To connect a session, you can use the command invoke-session by putting the command into one quote as follows:

$Results = Invoke-SSHCommand -SessionId 0 -Command 'uname -a'

It returns all the information about the uname command exactly as the command was entered into the console. unameis an Linux command that outputs the entire system’s information. Posh-SSH allows multiple open sessions simultaneously. Simply replace with the SessionId variable to identify the proper session. To view the sessions that are active you can use the Get-SSHSession command.



Run commands from an Linux server using the Posh-SSH PowerShell cmdlets.

The returned data is displayed in the form of an object. In order to obtain the output you want, make use of the Select-Object cmdlet, and then use the output property:

$Results|Select-Object Output

Although they are simple, these Posh SSH examples illustrate how a more sophisticated script could gather data regarding Linux hosts in order to create reports. report that includes a variety of information, such as processing and memory consumption.

Utilize Posh-SSH to upload your documents to Linux servers.

Administrators may use Posh SSH to perform crucial infrastructure tasks, for example, uploading files to groups of Linux servers in order to stage updates rather than manually uploading every individual file.

Posh-SSH supports a variety of choices for file transfer, such as SSH FTP as well as Secure Copy Protocol (SCP). The example below allows you to upload a file by using the SCP command. It only requires OpenSSH server functions.

Set-SCPItem Computername 192.168.83.128 Credit Card (Get-Credential Sysadmin) .update.zip The destination is"/tmp/"

The Posh-SSH plugin helps expand the capabilities of PowerShell to the Linux area. Windows administrators who are novices to running the systems need to understand some basic difference between the two OSes like the best way to handle files and be cognizant of the case-sensitivity issue in both the Windows and Linux side.

Further information regarding the Posh SSH module is available on the repository of GitHub.

Source: https://www.techtarget.com/searchwindowsserver/tip/These-Posh-SSH-examples-pave-the-way-to-Linux-management

You May Also Like

More From Author

+ There are no comments

Add yours