栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

更改 SSH 使用的 Shell

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更改 SSH 使用的 Shell

本文参考Choosing the shell that SSH uses? - Server Faulthttps://serverfault.com/questions/106722/choosing-the-shell-that-ssh-uses

以 Windows 为例,其默认的 Shell 是 CMD,如果要使用 Windows 系统自带的 PowerShell 5 的话,则

ssh -t user@host "powershell"

如果要使用新版的 PowerShell Core 的话,则

ssh -t user@host "pwsh"

如果要使用 Git Bash 或 WSL 的话,根据你的 Windows 系统设置 bash 为哪个,使用

ssh -t user@host "bash"

 即可连接 Git Bash 或 WSL。

如果要在 Windows 中更改 SSH 连接的默认 Shell 的话,参考OpenSSH Server Configuration for Windows | Microsoft Docshttps://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration

New-ItemProperty -Path "HKLM:SOFTWAREOpenSSH" -Name DefaultShell -Value "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -PropertyType String -Force

即可设置任意 Shell 为 OpenSSH for Windows 使用的默认 Shell。

如果使用的是 Linux 的话,则使用

ssh -t user@host 'zsh -l'

-t 表示的是强制使用伪TTY分配,-l 表示的是触发登录 Shell。此外,你还可以在你的 ~/.ssh/config 中修改 Host:

Host yourServer
    HostName 
    IdentityFile ~/.ssh/
    RemoteCommand zsh -l
    RequestTTY force
    User 
Host someHost
    HostName someIP
    IdentityFile ~/.ssh/somekey.pem
    RemoteCommand zsh -l -c 'sleep 1; source /tmp/somefile; zsh'
    PermitLocalCommand yes
    LocalCommand bash -c 'sftp %r@%h <<< "put /tmp/somefile /tmp/somefile"'
    RequestTTY force
    User someUser

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361435.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号