简体   繁体   English

如何从远程 SSH session 将数据发送到本地剪贴板

[英]How to send data to local clipboard from a remote SSH session

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first:) Borderline ServerFault 问题,但我正在编写一些 shell 脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数 *nixes 都有一个命令,可以让您通过管道/重定向 output 到本地剪贴板/粘贴板,并从中检索。 On OS X these commands are在 OS X 上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过 SSH 连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机 A。
  2. I open a terminal window我打开一个终端 window
  3. I SSH to Computer B我 SSH 到计算机 B
  4. I run a command on Computer B我在计算机 B 上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机 B 的 output 被重定向或自动复制到计算机 A 的剪贴板。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(颤抖)使用我的鼠标来 select 来自命令的文本,但我已经习惯了将 output 直接移到剪贴板的工作流程,我希望我的远程会话也一样。

Code is useful, but general approaches are appreciated as well.代码很有用,但一般方法也很受欢迎。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

If you use iTerm2 on the Mac, there is an easier way.如果你在 Mac 上使用iTerm2 ,有一个更简单的方法。 This functionality is built into iTerm2's Shell Integration capabilities via the it2copy command:此功能通过it2copy命令内置到 iTerm2 的Shell 集成功能中:

Usage: it2copy
          Copies to clipboard from standard input
       it2copy filename
          Copies to clipboard from file

To make it work, choose iTerm2-->Install Shell Integration menu item while logged into the remote host, to install it to your own account.要使其工作,请在登录远程主机时选择iTerm2-->Install Shell 集成菜单项,将其安装到您自己的帐户。 Once that is done, you'll have access to it2copy , as well as a bunch of other aliased commands that provide cool functionality.完成后,您将可以访问it2copy以及许多其他提供很酷功能的别名命令。

The other solutions here are good workarounds but this one is so painless in comparison.这里的其他解决方案是很好的解决方法,但相比之下,这个解决方案非常轻松。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same.大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索。 On OS X these commands are在OS X上,这些命令是

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server?无论如何,在通过SSH连接到另一台服务器时是否可以复制此功能? That is,那是,

  1. I'm using Computer A.我正在使用计算机A。
  2. I open a terminal window我打开一个终端窗口
  3. I SSH to Computer B我通过SSH连接到计算机B
  4. I run a command on Computer B我在计算机B上运行命令
  5. The output of Computer B is redirected or automatically copied to Computer A's clipboard.计算机B的输出将被重定向或自动复制到计算机A的剪贴板中。

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望远程会话也能做到这一点。

Code is useful, but general approaches are appreciated as well.代码是有用的,但也欢迎使用一般方法。

If you're working over eg a pod in a Kubernetes cluster and not direct SSH, so that there is no way for your to do a file transfer, you could use cat and then save the terminal output as text.如果您正在处理例如 Kubernetes 集群中的 pod 而不是直接 SSH,这样您就无法进行文件传输,您可以使用cat然后将终端 Z78E6221F63983D1356681DB3 保存为文本。 For example in macOS you can do Shell -> Export as text.例如,在 macOS 中,您可以执行 Shell -> 导出为文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从远程ssh连接上运行的tmux(复制模式)复制到本地剪贴板 - How do you copy from tmux (copy mode) running on a remote ssh connection to your local clipboard 如何通过ssh将命令行的输出从远程复制到本地剪贴板 - How to copy output of command line from remote, to local clipboard via ssh 如何使用sudo权限从Jenkins运行远程ssh会话? - How to run remote ssh session from Jenkins with sudo rights? How ansible copy file from remote windows to remote linux without local copy and ssh install in windows - How ansible copy file from remote windows to remote linux without local copy and ssh install in windows 如何将本地变量传递给远程ssh命令? - How to pass local variable to remote ssh commands? 如何通过创建不通过SSH的目录将文件从本地服务器复制到远程服务器? - How can I copy file from local server to remote with creating directories which absent via SSH? 通过 ssh 从远程 linux 机器运行本地 python 脚本 - run local python script from remote linux machine over ssh 在SSH中使用本地和远程变量 - Using Local and Remote Variable in SSH 如何使用 nohup 通过 ssh 在远程服务器上执行本地 bash 脚本 - How to execute a local bash script on remote server via ssh with nohup 如何在SSH命令中包含本地和远程变量 - How have both local and remote variable inside an SSH command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM