ssh远程执行shell命令


ssh远程执行

#通过ssh后,添加字符串格式命令,直接在远程机器上执行命令行
ssh -p 21 root@192.168.0.1 "cd workplace; ls -l;"

执行多行命令

# <<表示后面的内容作为输入, shell代码标识符,回车后显示heredoc
# 可进行多行命令编写,直至再遇到shell标识符,代码块结束
ssh -Tq -p 21 root@192.168.0.1 <<shell
heredoc> cd logs
heredoc> tail run.log
heredoc> exit
heredoc> shell

Pseudo-terminal will not be allocated because stdin is not a terminal

如果执命令行时,终端提示如上信息,伪终端将无法分配,因为标准输入不是终端,可以给ssh添加参数解决

ssh -Tq -p 21 root@192.168.0.1 
ssh -tt -p 21 root@192.168.0.1 


评论:
  • * * * Unlock Free Spins Today: https://www.pixelwise.one/index.php?w0trbk * * * hs=24a39bc4eb431c6e6dc853facaa6b873* ххх* 2025-06-03 23:06:31

    weaaqu

  • * * * <a href="https://www.pixelwise.one/index.php?w0trbk">Get Free Bitcoin Now</a> * * * hs=24a39bc4eb431c6e6dc853facaa6b873* ххх* 2025-06-03 23:06:32

    weaaqu