How to SSH into Linux Server executing Alias with Parameter using /.ssh/config file from PowerShell (Windows Terminal)

huangapple go评论62阅读模式
英文:

How to SSH into Linux Server executing Alias with Parameter using /.ssh/config file from PowerShell (Windows Terminal)

问题

I can not ssh into server using my .ssh/config file through Alias from my PowerShell Profile file and run some couple of commands.

I already have working my .ssh/config file to go into my linux server (With Key)

  • .ssh/config file
Host ubu
      Port 2200
      HostName 192.168.1.197
      User julio

Now I want to ssh into server using Alias from my PowerShell Profile file and run some updates commands

sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean

I try this unsuccesfully,

  • PowerShell Profile File
Function ubuFullUpdate {ssh ubu; sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean}
Set-Alias -Name ubu -Value ubuFullUpdate

Just go into server (.ssh/config work fine) and all next commands fail.

Function ubuFullUpdate {ssh -t -p 2200 julio@192.168.1.197 sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean}
Set-Alias -Name ubu -Value ubuFullUpdate

Go into server but just work sudo apt update and the following commands fail and flag error.

Normal error message in both cases

> The term 'sudo' is not recognized as a name of a cmdlet, function, script file, or executable program. Check
> the spelling of the name, or if a path was included, verify that the path is correct and try again.
>

I'm sure it's not sudo itself the failure, it's what follows from that point and being able to execute several consecutive commands

Happy Fixing!!

英文:

I can not ssh into server using my .ssh/config file through Alias from my PowerShell Profile file and run some couple of commands.

I already have working my .ssh/config file to go into my linux server (With Key)

  • .ssh/config file
Host ubu
      Port 2200
      HostName 192.168.1.197
      User julio

Now I want to ssh into server using Alias from my PowerShell Profile file and run some updates commands

sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean

I try this unsuccesfully,

  • PowerShell Profile File
Function ubuFullUpdate {ssh ubu; sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean}
Set-Alias -Name ubu -Value ubuFullUpdate

Just go into server (.ssh/config work fine) and all next commands fail.

Function ubuFullUpdate {ssh -t -p 2200 julio@192.168.1.197 sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoremove -y && sudo apt autoclean}
Set-Alias -Name ubu -Value ubuFullUpdate

Go into server but just work sudo apt update and the following commands fail and flag error.

Normal error message in both cases

> The term 'sudo' is not recognized as a name of a cmdlet, function, script file, or executable program. Check
> the spelling of the name, or if a path was included, verify that the path is correct and try again.
>

I'm sure it's not sudo itself the failure, it's what follows from that point and being able to execute several consecutive commands

Happy Fixing!!

答案1

得分: 0

I finally was able to find one easy solution (because like all in IT has more than one way to do it)

> 不需要 .ssh/config 文件

Function ubuFullUpdate {ssh -t -p 2200 <USERNAME>@<SERVERIPADRRESS> 'sudo apt update; sudo apt upgrade -y; sudo apt dist-upgrade; sudo apt autoremove -y; sudo apt autoclean'}
Set-Alias -Name ubu -Value ubuFullUpdate

ubuFullUpdate = 任何函数名称

ubu= 任何别名名称

英文:

I finally was able to find one easy solution (because like all in IT has more than one way to do it)

> No .ssh/config file needed

Function ubuFullUpdate {ssh -t -p 2200 &lt;USERNAME&gt;@&lt;SERVERIPADRRESS&gt; &#39;sudo apt update; sudo apt upgrade -y; sudo apt dist-upgrade; sudo apt autoremove -y; sudo apt autoclean&#39;}
Set-Alias -Name ubu -Value ubuFullUpdate

ubuFullUpdate = any function name

ubu= any alias name

huangapple
  • 本文由 发表于 2023年2月8日 12:03:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定