+
+ Transfer File Content Using Xclip in Terminal
+ + + +工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +diff --git a/content/post/transfer-file-content-using-xclip-in-terminal.md b/content/post/transfer-file-content-using-xclip-in-terminal.md new file mode 100644 index 00000000..1f6fb1e0 --- /dev/null +++ b/content/post/transfer-file-content-using-xclip-in-terminal.md @@ -0,0 +1,89 @@ +--- +title: "Transfer File Content Using Xclip in Terminal" +date: 2019-05-17T12:18:54+08:00 +draft: false + +noSummary: false +featuredImage: "https://h.cowbay.org/images/post-default-11.jpg" +categories: ['linux'] +tags: ['linux'] +author: "Eric Chang" +--- + +工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。 + +以前都是傻傻的用 scp 傳檔案 + +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行 + +早上研究了一下,順便做個筆記。 + + + +### 1. ssh 要加上 -X ### +不然會出現 + +``` +Error: Can't open display: (null) +``` + +這種錯誤訊息 + +``` +-X Enables X11 forwarding. This can also be specified on a per-host basis in a configuration file. + + X11 forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the user's X + authorization database) can access the local X11 display through the forwarded connection. An attacker may then be able to perform activi‐ + ties such as keystroke monitoring. + + For this reason, X11 forwarding is subjected to X11 SECURITY extension restrictions by default. Please refer to the ssh -Y option and the + ForwardX11Trusted directive in ssh_config(5) for more information. +``` + +### 2. remote 主機要安裝 xclip / xsel ### +``` +2019-05-17 10:12:20 [minion@hqs019 ~]$ sudo apt install xsel +Reading package lists... Done +Building dependency tree +Reading state information... Done +The following NEW packages will be installed: + xsel +0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded. +Need to get 19.0 kB of archives. +After this operation, 47.1 kB of additional disk space will be used. +Get:1 http://ftp.tw.debian.org/ubuntu bionic/universe amd64 xsel amd64 1.2.0-4 [19.0 kB] +Fetched 19.0 kB in 0s (80.3 kB/s) +Selecting previously unselected package xsel. +(Reading database ... 161032 files and directories currently installed.) +Preparing to unpack .../xsel_1.2.0-4_amd64.deb ... +Unpacking xsel (1.2.0-4) ... +Processing triggers for man-db (2.8.3-2ubuntu0.1) ... +Setting up xsel (1.2.0-4) ... + +2019-05-17 10:13:32 [minion@hqs019 ~]$ sudo apt install xclip +Reading package lists... Done +Building dependency tree +Reading state information... Done +The following NEW packages will be installed: + xclip +0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded. +Need to get 17.5 kB of archives. +After this operation, 52.2 kB of additional disk space will be used. +Get:1 http://ftp.tw.debian.org/ubuntu bionic/main amd64 xclip amd64 0.12+svn84-4build1 [17.5 kB] +Fetched 17.5 kB in 1s (16.2 kB/s) +Selecting previously unselected package xclip. +(Reading database ... 161038 files and directories currently installed.) +Preparing to unpack .../xclip_0.12+svn84-4build1_amd64.deb ... +Unpacking xclip (0.12+svn84-4build1) ... +Setting up xclip (0.12+svn84-4build1) ... +Processing triggers for man-db (2.8.3-2ubuntu0.1) ... +``` + +### 3.執行方式 + +執行以下指令,就可以把遠端的檔案內容傳送到「系統剪貼簿」,在本機就可以直接貼上了 + + +``` +cat copy_neonexus.csv |xclip -selection clipboard +``` diff --git a/public/404.html b/public/404.html index df2c25c1..20276832 100644 --- a/public/404.html +++ b/public/404.html @@ -115,6 +115,10 @@
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +
-
- 最近在做一台老機器的P2V
- -偏偏user說不能關機,所以我用dd + ssh 做線上移轉
- -這部份有空再來寫
- -只是因為原來的設定有用mdadm 做raid1
- -這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
- - - - - - - -
+
+ 最近在做一台老機器的P2V
+ +偏偏user說不能關機,所以我用dd + ssh 做線上移轉
+ +這部份有空再來寫
+ +只是因為原來的設定有用mdadm 做raid1
+ +這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
+ + + + + + + +
-
- Bookstack 是一套非常好用的線上”筆記”系統
- -他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
- -同時在圖書館內建立不同的”書籍”
- -而且支援 Markdown 語法
- -其他的方式像是在nextcloud上編輯 md檔案(字體太小)
- -或者是boostnote(只能在本機)
- -都或多或少有點小缺點
- -Bookstack則是沒有這些問題,不過就是系統「大」了點…
- -不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
- - - - - - - -
+
+ Bookstack 是一套非常好用的線上”筆記”系統
+ +他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
+ +同時在圖書館內建立不同的”書籍”
+ +而且支援 Markdown 語法
+ +其他的方式像是在nextcloud上編輯 md檔案(字體太小)
+ +或者是boostnote(只能在本機)
+ +都或多或少有點小缺點
+ +Bookstack則是沒有這些問題,不過就是系統「大」了點…
+ +不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
+ + + + + + + +
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +
-
- 最近在做一台老機器的P2V
- -偏偏user說不能關機,所以我用dd + ssh 做線上移轉
- -這部份有空再來寫
- -只是因為原來的設定有用mdadm 做raid1
- -這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
- - - - - - - -
+
+ 最近在做一台老機器的P2V
+ +偏偏user說不能關機,所以我用dd + ssh 做線上移轉
+ +這部份有空再來寫
+ +只是因為原來的設定有用mdadm 做raid1
+ +這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
+ + + + + + + +
-
- Bookstack 是一套非常好用的線上”筆記”系統
- -他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
- -同時在圖書館內建立不同的”書籍”
- -而且支援 Markdown 語法
- -其他的方式像是在nextcloud上編輯 md檔案(字體太小)
- -或者是boostnote(只能在本機)
- -都或多或少有點小缺點
- -Bookstack則是沒有這些問題,不過就是系統「大」了點…
- -不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
- - - - - - - -
+
+ Bookstack 是一套非常好用的線上”筆記”系統
+ +他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
+ +同時在圖書館內建立不同的”書籍”
+ +而且支援 Markdown 語法
+ +其他的方式像是在nextcloud上編輯 md檔案(字體太小)
+ +或者是boostnote(只能在本機)
+ +都或多或少有點小缺點
+ +Bookstack則是沒有這些問題,不過就是系統「大」了點…
+ +不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
+ + + + + + + +
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +
-
- 最近在做一台老機器的P2V
- -偏偏user說不能關機,所以我用dd + ssh 做線上移轉
- -這部份有空再來寫
- -只是因為原來的設定有用mdadm 做raid1
- -這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
- - - - - - - -
+
+ 最近在做一台老機器的P2V
+ +偏偏user說不能關機,所以我用dd + ssh 做線上移轉
+ +這部份有空再來寫
+ +只是因為原來的設定有用mdadm 做raid1
+ +這部份導致移轉過去proxmox 後,會出現raid degrade 導致無法正常開機
+ + + + + + + +
-
- Bookstack 是一套非常好用的線上”筆記”系統
- -他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
- -同時在圖書館內建立不同的”書籍”
- -而且支援 Markdown 語法
- -其他的方式像是在nextcloud上編輯 md檔案(字體太小)
- -或者是boostnote(只能在本機)
- -都或多或少有點小缺點
- -Bookstack則是沒有這些問題,不過就是系統「大」了點…
- -不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
- - - - - - - -
+
+ Bookstack 是一套非常好用的線上”筆記”系統
+ +他用圖書館/書本的概念,讓使用者可以建立自己的”圖書館”
+ +同時在圖書館內建立不同的”書籍”
+ +而且支援 Markdown 語法
+ +其他的方式像是在nextcloud上編輯 md檔案(字體太小)
+ +或者是boostnote(只能在本機)
+ +都或多或少有點小缺點
+ +Bookstack則是沒有這些問題,不過就是系統「大」了點…
+ +不過還好有人做成docker的方式來啟動,大大的降低了建置的難度(其實也沒有很難啦,只是要裝個PHP、弄個DB而已)
+ + + + + + + +
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + +不然會出現
+ +Error: Can't open display: (null)
+
+
+這種錯誤訊息
+ +-X Enables X11 forwarding. This can also be specified on a per-host basis in a configuration file.
+
+ X11 forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the user's X
+ authorization database) can access the local X11 display through the forwarded connection. An attacker may then be able to perform activi‐
+ ties such as keystroke monitoring.
+
+ For this reason, X11 forwarding is subjected to X11 SECURITY extension restrictions by default. Please refer to the ssh -Y option and the
+ ForwardX11Trusted directive in ssh_config(5) for more information.
+
+
+2019-05-17 10:12:20 [minion@hqs019 ~]$ sudo apt install xsel
+Reading package lists... Done
+Building dependency tree
+Reading state information... Done
+The following NEW packages will be installed:
+ xsel
+0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded.
+Need to get 19.0 kB of archives.
+After this operation, 47.1 kB of additional disk space will be used.
+Get:1 http://ftp.tw.debian.org/ubuntu bionic/universe amd64 xsel amd64 1.2.0-4 [19.0 kB]
+Fetched 19.0 kB in 0s (80.3 kB/s)
+Selecting previously unselected package xsel.
+(Reading database ... 161032 files and directories currently installed.)
+Preparing to unpack .../xsel_1.2.0-4_amd64.deb ...
+Unpacking xsel (1.2.0-4) ...
+Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
+Setting up xsel (1.2.0-4) ...
+
+2019-05-17 10:13:32 [minion@hqs019 ~]$ sudo apt install xclip
+Reading package lists... Done
+Building dependency tree
+Reading state information... Done
+The following NEW packages will be installed:
+ xclip
+0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded.
+Need to get 17.5 kB of archives.
+After this operation, 52.2 kB of additional disk space will be used.
+Get:1 http://ftp.tw.debian.org/ubuntu bionic/main amd64 xclip amd64 0.12+svn84-4build1 [17.5 kB]
+Fetched 17.5 kB in 1s (16.2 kB/s)
+Selecting previously unselected package xclip.
+(Reading database ... 161038 files and directories currently installed.)
+Preparing to unpack .../xclip_0.12+svn84-4build1_amd64.deb ...
+Unpacking xclip (0.12+svn84-4build1) ...
+Setting up xclip (0.12+svn84-4build1) ...
+Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
+
+
+執行以下指令,就可以把遠端的檔案內容傳送到「系統剪貼簿」,在本機就可以直接貼上了
+ +cat copy_neonexus.csv |xclip -selection clipboard
+
+
+
+
+ 工作上常會需要用ssh登入遠端主機檢查LOG,有必要的時候,還要把log複製回本機來處理。
+ +以前都是傻傻的用 scp 傳檔案
+ +之前就記得有這個xclip/xsel 可以用,但是一直沒有弄清楚怎麼執行
+ +早上研究了一下,順便做個筆記。
+ + + + + + + +