How to use windows Powershell and command prompt to SSH into devices 

Table of Contents

Introduction

SSH helps accessing the device Cli and it’s better than the telnet as it’s encrypted. Usually when trying to access linux and networking devices from the Windows machine we use tools like Putty and Secure CRT. Using the recent Windows releases we can directly SSH to those devices from the command prompt and the Powershell and don’t have to install 3rd party tools like secure CRT and the Putty.

In this Article we will cover examples on how to use the command prompt and the powershell to get SSH access to the devices.

Syntax for the SSH command usage

While using the SSH command we need to specify the username and device IP address or DNS name

ssh   <username>@<IP or DNS name of the device to access >

We can use either password for a username to access or we can set up a ssh key to make the access work as well. If you are using the password based authentication , when you execute the above command we will see a prompt to enter the password associated with the username 

Powershell SSH command 

To open a Powershell terminal  , you can type “powershell” on the search toolbar on your windows machine and click the “Windows Powershell”  app to open a terminal. Then type “ssh” in the powershell to verify the ssh client is installed on the powershell natively. You should see the output like the example below. 

PS C:\Users\Discovering_systems>ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

Practical example on how to get SSH access to devices from the Powershell 

In this example , we are using the powershell to access the device owning the ip address 192.168.44.154 through ssh using the root username. We can see that if the device is reachable and its ssh port 22 is also open , it processes the access request and prompts for the password. Once we entered the password we were able to get the access 

PS C:\Users\Discovering_systems> ssh root@192.168.44.154
root@192.168.44.154's password:
Last login: Thu Jun  8 10:12:53 2023 from 192.168.44.1

[root@discoveringsystems ~]#
[root@discoveringsystems ~]# cd /
[root@discoveringsystems /]# ls
bin   dev  home  lib64  mnt  packages    proc  run   srv  tmp  var
boot  etc  lib   media  opt  pcap-files  root  sbin  sys  usr
[root@discoveringsystems /]# exit
exit
logout
Connection to 192.168.44.154 closed.

Command prompt SSH command 

In most recent windows releases ssh command works in the Command prompt  as well.  

To open a command prompt , you can type “cmd” on the search toolbar on your windows machine and click the command prompt app to open a terminal. Then type “ssh” in the powershell to verify the ssh client is installed on the command prompt terminal natively. You should see the output like the example below. 

PS C:\Users\Discovering_systems>ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

Practical example on how to get SSH access to devices from the command prompt terminal

In this example , we are using the command prompt to access the device owning the ip address 192.168.44.154 through ssh using the root username. We can see that if the device is reachable and its ssh port 22 is also open , it processes the access request and prompts for the password. Once we entered the password we were able to get the access 

PS C:\Users\Discovering_systems> ssh root@192.168.44.154
root@192.168.44.154's password:
Last login: Thu Jun  8 10:32:21 2023 from 192.168.44.1

[root@discoveringsystems ~]# cd /
[root@discoveringsystems /]# ls
bin   dev  home  lib64  mnt  packages    proc  run   srv  tmp  var
boot  etc  lib   media  opt  pcap-files  root  sbin  sys  usr
[root@discoveringsystems /]# exit
exit
logout
Connection to 192.168.44.154 closed.

How to execute the command on a remote machine through ssh without logging into the cli 

The following example works both on the powershell and the command prompt. we are going to execute the command on the linux machine through ssh without logging into the cli. We executed the “ls /” command to show all the files and directories in the “/” path and the ssh access ended automatically after printing the output. This method helps a lot while we are running some automation scripts 

PS C:\Users\Discovering_systems>  ssh root@192.168.44.154 " ls / "
root@192.168.44.154's password:
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
packages
pcap-files
proc
root
run
sbin
srv
sys
tmp
usr
var
PS C:\Users\Discovering_systems> 

Conclusion

In this article we explored how to use the natively installed ssh client on the powershell and the command prompt to access the remote devices. If you are interested in other articles from us based on windows machine , please take a look at the following articles 

Leave a Comment

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