如何从远程SSH会话将数据发送到本地剪贴板 [英] How to send data to local clipboard from a remote SSH session
问题描述
Borderline ServerFault问题,但是我正在编程一些shell脚本,所以我先在这里尝试:)
大多数* nixes都有一个命令,使您可以将输出通过管道传输/重定向到本地剪贴板/粘贴板,并从中进行检索.在OS X上,这些命令是
pbcopy, pbpaste
在通过SSH连接到另一台服务器时,是否仍可以复制此功能?就是
- 我正在使用计算机A.
- 我打开一个终端窗口
- 我通过SSH连接到计算机B
- 我在计算机B上运行命令
- 计算机B的输出被重定向或自动复制到计算机A的剪贴板中.
是的,我知道我可以(使用鼠标)从命令中选择文本,但是我已经习惯了将输出直接拖到剪贴板的工作流程,因此我希望遥控器也可以这样做会议.
代码是有用的,但也欢迎使用一般方法.
我正在恢复此线程,因为我一直在寻找相同的解决方案,并且已经找到了一种适用于我的解决方案.对
它要求将您的桌面配置为ssh服务器(我留给您和Google使用).如果您已经设置了ssh密钥以促进ssh的快速使用,则要容易得多,最好使用每个会话的密码短语或任何您的安全需要. 其他示例: 为方便起见,我创建了一个bash文件来缩短管道后所需的文本: 在我的情况下,我使用的是特殊命名的键 我将其保存为文件名 cb (我的助记符(ClipBoard).将脚本放置在路径中的某个位置,使其可执行并执行: Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first :) Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same. On OS X these commands are Is there anyway to replicate this functionality while SSHed into another server? That is, 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. I'm resurrecting this thread because I've been looking for the same kind of solution, and I've found one that works for me. It's a minor modification to a suggestion from OSX Daily. In my case, I use Terminal on my local OSX machine to connect to a linux server via SSH. Like the OP, I wanted to be able to transfer small bits of text from terminal to my local clipboard, using only the keyboard. The essence of the solution: When run in an ssh session to a remote computer, this command takes the output of commandThatMakesOutput (e.g. ls, pwd) and pipes the output to the clipboard of the local computer (the name or IP of "desktop"). In other words, it uses nested ssh: you're connected to the remote computer via one ssh session, you execute the command there, and the remote computer connects to your desktop via a different ssh session and puts the text to your clipboard. It requires your desktop to be configured as an ssh server (which I leave to you and google). It's much easier if you've set up ssh keys to facilitate fast ssh usage, preferably using a per-session passphrase, or whatever your security needs require. Other examples: For convenience, I've created a bash file to shorten the text required after the pipe: In my case, i'm using a specially named key I saved it with the file name cb (my mnemonic (ClipBoard). Put the script somewhere in your path, make it executable and voila:
这篇关于如何从远程SSH会话将数据发送到本地剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!ls | ssh desktopIpAddress pbcopy
pwd | ssh desktopIpAddress pbcopy
#!/bin/bash
ssh desktop pbcopy
ls | cb
pbcopy, pbpaste
commandThatMakesOutput | ssh desktop pbcopy
ls | ssh desktopIpAddress pbcopy
pwd | ssh desktopIpAddress pbcopy
#!/bin/bash
ssh desktop pbcopy
ls | cb