[英]How can I copy the contents of a file directly into my Windows clipboard when I'm running the command on a remote Linux machine via ssh in Git Bash?
我使用的是 Windows 10。我打開 Git Bash,然后 ssh 進入 Ubuntu 服務器。 我經常想復制一個大文本文件的全部內容。
有時我寧願快速將內容復制到剪貼板,而不是使用 scp 將文件下載到我的 Windows 機器上。
使用cat
然后滾動數千行然后手動復制到剪貼板是可能的,但不切實際。
我寧願將cat
傳遞給將輸出復制到我的 Windows 剪貼板的命令。 或者調用一些其他命令,如xclip
。
https://unix.stackexchange.com/questions/211817/copy-the-contents-of-a-file-into-the-clipboard-without-displaying-its-contents以及如何直接復制命令的輸出到我的剪貼板? 是類似的問題,但xclip
會導致此錯誤:
xclip -sel c < /etc/php/7.4/cli/php.ini
Error: Can't open display: (null)
評論后更新:
https://stackoverflow.com/a/39556508/470749很有趣,但X11Forwarding yes
已經在我的服務器配置中,當我將ForwardX11 yes
添加到~/.ssh/config
然后運行ssh -v -X -t -i ~/.ssh/id_rsa myuser@■■.■■■.■■■.■■
,我仍然得到:
debug1: No xauth program.
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
然后當我運行xsel -b < /etc/php/7.4/cli/php.ini
:
xsel: Can't open display: (null)
: Inappropriate ioctl for device
也許在 Windows 上的 Git Bash 中使用 X 會話? 將進一步幫助我。
您需要 Windows 主機上的 X 服務器和 ssh 連接中的 X 隧道。 xclip
會將剪貼板發送到您的 X 服務器,服務器會將其提供給 Windows。
export DISPLAY=localhost:0.0
/etc/ssh/sshd.config
遠程節點上具有行X11Forwarding yes
ssh
添加-Y
標志: ssh -Y <server_address>
雖然 Stack Overflow 上已經有一些食譜,但還是有一個小問題。 注意DISPLAY=localhost:0.0
。 如果省略localhost
,即export DISPLAY=:0.0
,則xclip
將在遠程節點上失敗:
connect /tmp/.X11-unix/X0: No such file or directory xterm: Xt error: Can't open display: localhost:10.0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.