在远程登录到 linux 服务器时绕过 ~/.profile

And*_*ton 33 linux ssh .profile putty

~/.profile使用 ssh 或 putty 登录远程 Linux 服务器时,有没有办法绕过或阻止执行?

小智 31

对于 bash:

$ ssh hostname "bash --noprofile"
Run Code Online (Sandbox Code Playgroud)

  • 我想你还需要 `-t` 选项。 (6认同)
  • ssh -t hostname "bash --noprofile" 。如果 -t 不存在,我会收到错误“标准输入必须是 tty”。 (2认同)

Jac*_* M. 14

如果您正在寻找禁用所有登录脚本,您可以使用--noprofile标志来禁止/etc/profile~/.profile等,--norc以禁用~/.bashrc,像这样:

$ ssh 127.0.0.1 "bash --noprofile --norc"
Run Code Online (Sandbox Code Playgroud)

请记住,如果可用,您还可以启动替代 shell。搞砸后我不得不使用它chsh

$ ssh 127.0.0.1 sh
Run Code Online (Sandbox Code Playgroud)

这很可能会让你进入一个空白的外壳(没有提示),所以给它一个ls以确保它正在工作。