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

Linux中的5個SSH別名例子

系統(tǒng) Linux
作為一個 Linux 用戶,我們常用 ssh 命令 來登入遠(yuǎn)程機(jī)器。ssh 命令你用得越多,你在鍵入一些重要的命令上花的時間也越多。我們可以用 定義在你的 .bashrc 文件里的別名 或函數(shù)來大幅度縮減花在命令行界面(CLI)的時間。但這不是最佳解決之道。最佳辦法是在 ssh 配置文件中使用 SSH 別名 。

[[225419]]

作為一個 Linux 用戶,我們常用 ssh 命令 來登入遠(yuǎn)程機(jī)器。ssh 命令你用得越多,你在鍵入一些重要的命令上花的時間也越多。我們可以用 定義在你的 .bashrc 文件里的別名 或函數(shù)來大幅度縮減花在命令行界面(CLI)的時間。但這不是***解決之道。***辦法是在 ssh 配置文件中使用 SSH 別名

這里是我們能把 ssh 命令用得更好的幾個例子。

ssh 登入到 AWS(譯注:Amazon Web Services,亞馬遜公司旗下云計算服務(wù)平臺)實(shí)例的連接是一種痛。僅僅輸入以下命令,每次也完全是浪費(fèi)你時間。

  1. ssh -p 3000 -i /home/surendra/mysshkey.pem ec2-user@ec2-54-20-184-202.us-west-2.compute.amazonaws.com

縮短到:

  1. ssh aws1

調(diào)試時連接到系統(tǒng)。

  1. ssh -vvv the_good_user@red1.taggle.abc.com.au

縮短到:

  1. ssh xyz

在本篇中,我們將看到如何不使用 bash 別名或函數(shù)實(shí)現(xiàn) ssh 命令的縮短。ssh 別名的主要優(yōu)點(diǎn)是所有的 ssh 命令快捷方式都存儲在一個單一文件,如此就易于維護(hù)。其他優(yōu)點(diǎn)是 對于類似于 SSH 和 SCP 的命令 我們能用相同的別名。

在我們進(jìn)入實(shí)際配置之前,我們應(yīng)該知道 /etc/ssh/ssh_config/etc/ssh/sshd_config~/.ssh/config 文件三者的區(qū)別。以下是對這些文件的解釋。

 

/etc/ssh/ssh_config 和 ~/.ssh/config 間的區(qū)別

系統(tǒng)級別的 SSH 配置項(xiàng)存放在 /etc/ssh/ssh_config,而用戶級別的 SSH 配置項(xiàng)存放在 ~/.ssh/config 文件中。

 

/etc/ssh/sshconfig 和 /etc/ssh/sshdconfig 間的區(qū)別

系統(tǒng)級別的 SSH 配置項(xiàng)是在 /etc/ssh/ssh_config 文件中,而系統(tǒng)級別的 SSH 服務(wù)端配置項(xiàng)存放在 /etc/ssh/sshd_config 文件。

 

在 ~/.ssh/config 文件里配置項(xiàng)的語法

~/.ssh/config 文件內(nèi)容的語法:

  1. 配置項(xiàng)
  2. 配置項(xiàng) 1 2

例 1: 創(chuàng)建主機(jī)(www.linuxnix.com)的 SSH 別名

編輯 ~/.ssh/config 文件寫入以下內(nèi)容:

  1. Host tlj
  2. User root
  3. HostName 18.197.176.13
  4. port 22

保存此文件。

以上 ssh 別名用了

  1. tlj 作為一個別名的名稱
  2. root 作為將要登入的用戶
  3. 18.197.176.13 作為主機(jī)的 IP 地址
  4. 22 作為訪問 SSH 服務(wù)的端口

輸出:

  1. sanne@Surendras-MacBook-Pro:~ > ssh tlj
  2. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
  3. * Documentation: https://help.ubuntu.com
  4. * Management: https://landscape.canonical.com
  5. * Support: https://ubuntu.com/advantage
  6. Get cloud support with Ubuntu Advantage Cloud Guest:
  7. http://www.ubuntu.com/business/services/cloud
  8. Last login: Sat Oct 14 01:00:43 2017 from 20.244.25.231
  9. root@linuxnix:~# exit
  10. logout
  11. Connection to 18.197.176.13 closed.

例 2: 不用密碼用 ssh 密鑰登到系統(tǒng)要用 IdentityFile

例:

  1. Host aws
  2. User ec2-users
  3. HostName ec2-54-200-184-202.us-west-2.compute.amazonaws.com
  4. IdentityFile ~/Downloads/surendra.pem
  5. port 22

例 3: 對同一主機(jī)使用不同的別名。在下例中,我們對同一 IP/主機(jī) 18.197.176.13 用了 tljlinuxnixlinuxnix.com 三個別名。

~/.ssh/config 文件內(nèi)容

  1. Host tlj linuxnix linuxnix.com
  2. User root
  3. HostName 18.197.176.13
  4. port 22

輸出:

  1. sanne@Surendras-MacBook-Pro:~ > ssh tlj
  2. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
  3. * Documentation: https://help.ubuntu.com
  4. * Management: https://landscape.canonical.com
  5. * Support: https://ubuntu.com/advantage
  6. Get cloud support with Ubuntu Advantage Cloud Guest:
  7. http://www.ubuntu.com/business/services/cloud
  8. Last login: Sat Oct 14 01:00:43 2017 from 220.244.205.231
  9. root@linuxnix:~# exit
  10. logout
  11. Connection to 18.197.176.13 closed.
  12. sanne@Surendras-MacBook-Pro:~ > ssh linuxnix.com
  13. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
  14. * Documentation: https://help.ubuntu.com
  15. * Management: https://landscape.canonical.com
  16. * Support: https://ubuntu.com/advantage
  1. Get cloud support with Ubuntu Advantage Cloud Guest:
  2. http://www.ubuntu.com/business/services/cloud
  3. Last login: Sun Oct 15 20:31:08 2017 from 1.129.110.13
  4. root@linuxnix:~# exit
  5. logout
  6. Connection to 138.197.176.103 closed.
  7. [6571] sanne@Surendras-MacBook-Pro:~ > ssh linuxnix
  8. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
  9. * Documentation: https://help.ubuntu.com
  10. * Management: https://landscape.canonical.com
  11. * Support: https://ubuntu.com/advantage
  12. Get cloud support with Ubuntu Advantage Cloud Guest:
  13. http://www.ubuntu.com/business/services/cloud
  14. Last login: Sun Oct 15 20:31:20 2017 from 1.129.110.13
  15. root@linuxnix:~# exit
  16. logout
  17. Connection to 18.197.176.13 closed.

例 4: 用相同的 SSH 別名復(fù)制文件到遠(yuǎn)程系統(tǒng)

語法:

  1. scp <文件名> <ssh_別名>:<位置>

例子:

  1. sanne@Surendras-MacBook-Pro:~ > scp abc.txt tlj:/tmp
  2. abc.txt 100% 12KB 11.7KB/s 00:01
  3. sanne@Surendras-MacBook-Pro:~ >

若我們已經(jīng)將 ssh 主機(jī)設(shè)置好一個別名,由于 sshscp 兩者用幾乎相同的語法和選項(xiàng),scp 也可以輕易使用。

請?jiān)谙旅鎳L試從本機(jī) scp 一個文件到遠(yuǎn)程機(jī)器。

例 5: 解決 Linux 中的 SSH 超時問題。默認(rèn)情況,如果你不積極地使用終端,你的 ssh 登入就會超時

SSH 超時問題 是一個更痛的點(diǎn)意味著你在一段時間后不得不重新登入到遠(yuǎn)程機(jī)器。我們能在 ~/.ssh/config 文件里邊恰當(dāng)?shù)卦O(shè)置 SSH 超時時間來使你的會話不管在什么時間總是激活的。我們將用 2 個能保持會話存活的 SSH 選項(xiàng)來實(shí)現(xiàn)這一目的。之一是 ServerAliveInterval 保持你會話存活的秒數(shù)和 ServerAliveCountMax 在(經(jīng)歷了一個)給定數(shù)值的會話之后初始化會話。

  1. ServerAliveInterval A
  2. ServerAliveCountMax B

例:

  1. Host tlj linuxnix linuxnix.com
  2. User root
  3. HostName 18.197.176.13
  4. port 22
  5. ServerAliveInterval 60
  6. ServerAliveCountMax 30

在下篇中我們將會看到一些其他的退出方式。 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2019-05-14 11:00:07

LinuxSSH別名

2013-11-13 13:55:16

Linux命令grep

2018-10-12 10:40:45

LinuxBash命令

2017-06-22 08:58:51

Hadoopssh+IPssh+

2018-01-22 09:12:18

Linuxbashssh

2021-05-21 09:05:56

Linux創(chuàng)建永久別名

2014-03-17 17:27:51

Linux mvLinux 命令

2018-04-27 10:55:52

2019-06-25 08:42:13

Linux命令指令

2023-06-06 19:01:38

縮寫ShellLinux

2015-09-28 11:22:55

命令行補(bǔ)全Linux

2018-01-16 10:08:25

Linuxbashshell

2018-08-03 11:07:52

dd命令備份Linux系統(tǒng)

2013-12-06 17:39:49

Linuxps命令

2020-10-15 19:10:05

LinuxAPI函數(shù)

2019-02-21 19:00:49

LinuxSSH圖形界面工具

2009-12-04 19:33:53

2009-09-03 14:04:12

LinuxSSH程管理

2015-07-27 09:45:46

Linux桌面環(huán)境

2014-09-01 11:08:34

LinuxSSH
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 久久久久91 | 99免费| 91九色在线观看 | 97超碰成人 | 国产在线观看不卡一区二区三区 | 九九免费 | 九九九视频精品 | 狼色网 | 欧美日韩在线观看视频 | 欧美激情精品久久久久久变态 | 久久99视频免费观看 | 久久视频精品在线 | 久久人 | 久久四虎 | 深夜福利影院 | 成人伊人网 | 亚洲免费一 | 精品亚洲国产成av人片传媒 | 久久久夜夜夜 | 在线播放中文字幕 | 成人av一区二区在线观看 | 久久久www成人免费精品 | 欧美不卡在线 | 亚洲精品自在在线观看 | 一区二区亚洲 | 亚洲导航深夜福利涩涩屋 | 黄色成人免费在线观看 | 免费看av大片 | 成人av电影天堂 | 免费国产一区 | 超碰最新在线 | 久久久精品网站 | www97影院 | 国产精品日韩在线观看 | 一区二区三区四区在线 | 国产小视频在线观看 | 国产美女h视频 | 国产高清视频一区二区 | 欧美视频在线播放 | 久久久这里只有17精品 | 欧美精品久久 |