Developing an SSH Configuration Helper with PowerShell

Developing an SSH Configuration Helper with PowerShell

Original article and the source code of the SSH Configuration PowerShell Script published at Kiev repo on my GitHub account (polatengin).

In projects, we usually need to open SSH connections to remote systems.

For example, we can open an SSH connection to a remote machine from within the Visual Studio Code (you need to have Remote Development extension pack) and develop the project inside of the remote machine.

This scenario allows us to have a thin machine, but still, develop the project with a much more powerful machine with lots of RAMCPU and even GPU resources on Azure.

But to do that, we need to edit SSH Configuration file

We can find SSH Configuration file in ~/.ssh/config or C:\Users\{USER}\.ssh\config path

Configuration Helper

You can use Configuration Helper PowerShell Script to make it easier to edit SSH Configuration file

Menu

Reference: ssh_config.ps1#L40

You can choose 1 of the following Menu Items

No alt text provided for this image

Login to Azure

Reference: ssh_config.ps1#L77

You can login to Azure Portal via Azure CLI to access to the VMs running on Azure.

It's checking if the user is already logged-in to the Azure Portal, if not, it launches a new browser page to login to the Azure Portal.

If only 1 subscription is available for the user, it selects that subscription, if there is more than 1 subscription, it asks the user to choose one of them, and, it sets that subscription as Default.

So, all the upcoming commands will be executed on selected subscription, such as, getting the list of VMs, etc.

List VM Machines

Reference: ssh_config.ps1#L108

It's getting all the VMs on Azure Subscription and list them with Names and Power States

Start VM Machine(s)

Reference: ssh_config.ps1#L120

It's getting all the VMs on Azure Subscription, list them with checkboxes, selected VMs will be started

Stop VM Machine(s)

Reference: ssh_config.ps1#L133

It's getting all the VMs on Azure Subscription, list them with checkboxes, selected VMs will be stopped

Clean SSH Configuration File

Reference: ssh_config.ps1#L146

It parse the SSH Configuration file and creates a ConfigItem array.

Lists ConfigItem array with checkboxes, selected ConfigItems will be preserved, others will be removed from the SSH Configuration file

Add SSH Config for Azure VMs

Reference: ssh_config.ps1#L232

It gets all the VMs on the Azure Subscription, lists them with checkboxes, for the selected VMs a new ConfigItem element will be created.

All the ConfigItems will be appended to the SSH Configuration file

Help

Reference: ssh_config.ps1#L281

No alt text provided for this image

References

Write-Menu function for PowerShell (created by QuietusPlus) helped a-lot during the development of this script.

要查看或添加评论,请登录

Engin Polat的更多文章

  • Run Jenkins on Azure Container Instances

    Run Jenkins on Azure Container Instances

    Original article and the source code of the project published at Amsterdam repo on my GitHub account (polatengin). With…

  • Developing a webpage similar to keycode.info and serving it in a Docker Container

    Developing a webpage similar to keycode.info and serving it in a Docker Container

    Original article and the source code of the project published at Madrid repo on my GitHub account (polatengin). Not :…

    2 条评论
  • Documentation Conventions

    Documentation Conventions

    Original article published at Project Standards repo on my GitHub account (polatengin), you can find it on…

  • Bash Scripting Conventions

    Bash Scripting Conventions

    Original article published at Project Standards repo on my GitHub account (polatengin), you can find it on Bash…

    1 条评论

社区洞察

其他会员也浏览了