Connecting to a Hosting Server with PowerShell


If you have been connecting to your server like this :

ssh user@123.45.67.89

This can be done using Powershell Profiles.

PowerShell profiles can save time, especially if you frequently use specific commands or configurations. To create Profile follow these steps :

Step 1 : Open PowerShell with administrative privileges.

Step 2 : Run the following command to check if you already have a profile:

Test-Path $profile

If it returns False, you don’t have a profile.

If it returns True, you already have a profile.

Step 3 : If you don’t have a profile, create one using this command:

New-Item -Path $profile -Type File -Force

This command creates a profile file in the default location for your user profile, usually under :

$Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 // on windows

If you already have profile, use this command to open PS File in notepad

notepad $PROFILE

Step 4 : In Microsoft.PowerShell_profile.ps1 file create function like this :

function my_server{
    Start-Process ssh user@123.45.67.89
}

Note: You can give any name to function and replace ip with your IP

Shared Hosting

For Shared Hosting you may need to do this:


function my_server{
    Start-Process ssh -ArgumentList "-p", "126589", "user@123.45.67.89"
}

Note -ArgumentList "-p", "126589".

Here 126589 is shared hosting's port and can be found in SSH details on your hosting dashboard.

Step 5 : To allow the profile script to run when PowerShell opens. You can change the execution policy using:

Set-ExecutionPolicy RemoteSigned