如何透過 ssh 登入一台機器並同時對該機器上的檔案進行 cat 處理?

如何透過 ssh 登入一台機器並同時對該機器上的檔案進行 cat 處理?

基本上我想遠端cat一個文件,這就是我到目前為止所擁有的。這不起作用。我對這一切都很陌生:

echo /root/.ssh/id_rsa.pub | ssh root@HOSTNAME "cat >> /root/.ssh/authorized_keys

答案1

不使用echo,使用cat

cat /root/.ssh/id_rsa.pub | ssh root@HOSTNAME "cat >> /root/.ssh/authorized_keys"
  • echo /root/.ssh/id_rsa.pub將輸出字串 /root/.ssh/id_rsa.pub
  • cat /root/.ssh/id_rsa.pub將輸出 /root/.ssh/id_rsa.pub 的內容

  • ssh-copy-id -i my/alternate/pub.key root@HOSTNAME可能是解決方案,第一次會詢問您密碼。

答案2

在伺服器之間設定信任後,您可以使用 ssh 命令來擷取文件

ssh-keygen -t rsa
ssh-copy-id [email protected]
ssh -l username server.ip.addr "cat file.txt"

相關內容