成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

通過ssh會話執行bash別名

系統 Linux
SSH 客戶端 (ssh) 是一個登錄遠程服務器并在遠程系統上執行 shell 命令的 Linux/Unix 命令。它被設計用來在兩個非信任的機器上通過不安全的網絡(比如互聯網)提供安全的加密通訊。

[[217825]]

我在遠程主機上上設置過一個叫做 file_repl 的 bash 別名 。當我使用 ssh 命令登錄遠程主機后,可以很正常的使用這個別名。然而這個 bash 別名卻無法通過 ssh 來運行,像這樣:

  1. $ ssh vivek@server1.cyberciti.biz file_repl
  2. bashfile_replcommand not found

我要怎樣做才能通過 ssh 命令運行 bash 別名呢?

SSH 客戶端 (ssh) 是一個登錄遠程服務器并在遠程系統上執行 shell 命令的 Linux/Unix 命令。它被設計用來在兩個非信任的機器上通過不安全的網絡(比如互聯網)提供安全的加密通訊。

 

如何用 ssh 客戶端執行命令

通過 ssh 運行 free 命令或 date 命令 可以這樣做:

  1. $ ssh vivek@server1.cyberciti.biz date

結果為:

  1. Tue Dec 26 090250 UTC 2017

或者:

  1. $ ssh vivek@server1.cyberciti.biz free -h

結果為:

  1. total used free shared buff/cache available
  2. Mem2.0G 428M 138M 145M 1.4G 1.1G
  3. Swap0B 0B 0B

 

理解 bash shell 以及命令的類型

bash shell 共有下面幾類命令:

  1. 別名,比如 ll
  2. 關鍵字,比如 if
  3. 函數 (用戶自定義函數,比如 genpasswd
  4. 內置命令,比如 pwd
  5. 外部文件,比如 /bin/date

type 命令command 命令 可以用來查看命令類型:

  1. $ type -a date
  2. date is /bin/date
  3. $ type -a free
  4. free is /usr/bin/free
  5. $ command -V pwd
  6. pwd is a shell builtin
  7. $ type -a file_repl
  8. is aliased to `sudo -i /shared/takes/master.replication'

datefree 都是外部命令,而 file_replsudo -i /shared/takes/master.replication 的別名。你不能直接執行像 file_repl 這樣的別名:

  1. $ ssh user@remote file_repl

 

在 Unix 系統上無法直接通過 ssh 客戶端執行 bash 別名

要解決這個問題可以用下面方法運行 ssh 命令:

  1. $ ssh -t user@remote /bin/bash -ic 'your-alias-here'
  2. $ ssh -t user@remote /bin/bash -ic 'file_repl'

ssh 命令選項:

bash shell 的選項:

  • -i:運行交互 shell,這樣 shell 才能運行 bash 別名。
  • -c:要執行的命令取之于***個非選項參數的命令字符串。若在命令字符串后面還有其他參數,這些參數會作為位置參數傳遞給命令,參數從 $0 開始。

總之,要運行一個名叫 ll 的 bash 別名,可以運行下面命令:

  1. $ ssh -t vivek@server1.cyberciti.biz -ic 'll'

結果為:

Running bash aliases over ssh based session when using Unix or Linux ssh cli

Running bash aliases over ssh based session when using Unix or Linux ssh cli

下面是我的一個 shell 腳本的例子:

  1. #!/bin/bash
  2. I="tags.deleted.410"
  3. O="/tmp/https.www.cyberciti.biz.410.url.conf"
  4. box="vivek@server1.cyberciti.biz"
  5. [!-f "$I" ] && { echo "$I file not found。"; exit 10; }
  6. >$O
  7. cat "$I" | sort | uniq | while read -r u
  8. do
  9. uu="${u##https://www.cyberciti.biz}"
  10. echo "~^$uu 1;" >>"${O}"
  11. done
  12. echo "Config file created at ${O} and now updating remote nginx config file"
  13. scp "${O}" ${box}:/tmp/
  14. ssh ${box} /usr/bin/lxc file push /tmp/https.www.cyberciti.biz.410.url.conf nginx-container/etc/nginx/
  15. ssh -t ${box} /bin/bash -ic 'push_config_job'

 

相關資料

更多信息請輸入下面命令查看 OpenSSH 客戶端bash 的 man 幫助

  1. $ man ssh
  2. $ man bash
  3. $ help type
  4. $ help command 
責任編輯:龐桂玉 來源: Linux中國
相關推薦

2010-06-23 17:16:33

Linux Bash

2019-08-05 10:00:13

LinuxBash命令

2018-01-16 10:08:25

Linuxbashshell

2023-09-11 17:39:35

SSH服務TCP

2018-10-12 10:40:45

LinuxBash命令

2020-03-03 22:15:58

byobuSSH會話Linux

2019-05-14 11:00:07

LinuxSSH別名

2022-11-18 08:55:33

2018-04-10 09:06:45

LinuxSSH別名

2010-09-17 09:24:30

PowerShellSSH

2020-03-01 17:49:16

Linux腳本語言操作系統

2017-06-22 08:58:51

Hadoopssh+IPssh+

2020-12-28 06:29:31

Bash互動游戲Linux

2022-11-01 16:26:25

Linux命令腳本

2022-04-10 22:50:20

SSHLinux會話

2020-02-24 21:46:09

ChromiumFirefox桌面應用

2022-03-11 13:28:54

SSHLinux命令

2021-01-31 09:52:49

SSH監控網絡攻擊

2014-09-26 15:41:51

2010-09-14 17:35:52

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 男人的天堂久久 | 中文字幕乱码一区二区三区 | 国产成人jvid在线播放 | 久久久久国产精品一区三寸 | 国产网站在线免费观看 | 一区二区成人 | 国产亚洲二区 | 五月天婷婷丁香 | 久久亚洲一区二区三区四区 | 在线四虎 | 亚洲欧美中文字幕在线观看 | 久久毛片 | 免费视频一区二区 | 亚洲成人一区 | av中文在线播放 | 亚洲精品一二区 | 国产97碰免费视频 | 国产一级视屏 | 97久久精品| 国产91视频免费 | 一区二区三区精品 | 亚洲一区久久 | 亚洲 中文 欧美 日韩 在线观看 | 午夜网 | 国产一区亚洲 | 91色视频在线观看 | 国产欧美在线一区二区 | 欧美中文字幕一区二区三区 | 精品国产欧美一区二区三区成人 | 欧美1区2区 | 一区二区三区欧美在线 | 亚洲永久字幕 | 亚洲自拍偷拍欧美 | 翔田千里一区二区 | 91精品国产综合久久久久久丝袜 | 国产乡下妇女做爰 | 欧美一级淫片免费视频黄 | 在线免费观看亚洲 | 国产黑丝av| 久久九九99 | 一区二区三区四区在线视频 |