1. 程式人生 > >How to Install and Configure OpenSSH Server In Linux

How to Install and Configure OpenSSH Server In Linux

標題:在Linux中安裝和配置OpenSSH伺服器

Install OpenSSH in Linux  & 在Linux計算機中安裝OpenSSH

 

Being a network administrator requires a deep knowledge about remote login protocols such as rlogintelnet and ssh. The one I will discuss in this article is ssh, a secure remote protocol which is used to work remotely on other machines or transfer data between computers using 

SCP (Secure Copy) command. But, what is OpenSSH and how to install it in your Linux distribution?

作為網路管理員需要深入瞭解遠端登入協議,如rlogintelnetssh。我將在本文中討論的是ssh,一種安全的遠端協議,用於在其他計算機上遠端工作或使用SCP(安全複製)命令在計算機之間傳輸資料。但是,什麼是OpenSSH以及如何在Linux發行版中安裝它?

 

What is OpenSSH?

 

OpenSSH

 is a free open source set of computer tools used to provide secure and encrypted communication over a computer network by using the ssh protocol. Many people, new to computers and protocols, create a misconception about OpenSSH, they think it is a protocol, but it is not, it is a set of computer programs that use the ssh protocol
.

 

OpenSSH is developed by the Open BSD group and it is released under Simplified BSD License. A main factor which has made possible for OpenSSH to be used so much among system administrators is its multi-platform capability and very useful nice features it has. The latest version is OpenSSH 6.4 which has been released on November 8, 2013.

 

This version of OpenSSH comes with many new features and patches, so if you already use OpenSSH for administering your machines, I suggest you to do an upgrade.

 

什麼是OpenSSH?

 

OpenSSH是一套免費的開源計算機工具,通過使用ssh協議在計算機網路上提供安全和加密的通訊。許多人,不熟悉計算機和協議,對OpenSSH產生誤解,他們認為這是一種協議,但事實並非如此,它是一組使用ssh協議的計算機程式。

OpenSSH由Open BSD組開發,並在簡化BSD許可釋出。使OpenSSH在系統管理員中得到充分利用的一個主要因素是它的多平臺功能和非常有用的功能。最新版本是OpenSSH 6.4,已於2013年11月8日釋出

此版本的OpenSSH附帶了許多新功能和補丁,因此如果您已經使用OpenSSH來管理您的計算機,我建議您進行升級。

 

Why Use OpenSSH And Over Telnet Or Ftp?

 

The most important reason why should use OpenSSH tools over ftp and telnet is that all communications and user credentials using OpenSSH are encrypted, they are also protected from man in the middle attacks. If a third party tries to intercept your connection, OpenSSH detects it and informs you about that.

 

為什麼使用OpenSSH而不是Telnet或Ftp?

為什麼要使用的最重要原因是:OpenSSH的所有的通訊和使用者證書是進行加密過的,保護計算機免受中間人攻擊。如果第三方試圖攔截您的連線,OpenSSH會檢測到它並通知您。

 

What Are Some Of The OpenSSH Features?

  1. Secure Communication
  2. Strong Encryption (3DESBlowfishAESArcfour)
  3. X11 Forwarding (encrypt X Window System traffic)
  4. Port Forwarding (encrypted channels for legacy protocols)
  5. Strong Authentication (Public Key, One-Time Password and Kerberos Authentication)
  6. Agent Forwarding (Single-Sign-On)
  7. Interoperability (Compliance with SSH 1.3, 1.5, and 2.0 protocol Standards)
  8. SFTP client and server support in both SSH1 and SSH2 protocols.
  9. Kerberos and AFS Ticket Passing
  10. Data Compression

 

OpenSSH具有哪些功能?

  1. 安全通訊
  2. 強加密(3DESBlowfishAESArcfour
  3. X11轉發(加密X Window系統流量)
  4. 埠轉發(傳統協議的加密通道)
  5. 強身份驗證(公鑰,一次性密碼和Kerberos身份驗證)
  6. 代理轉發(單點登入
  7. 互操作性(符合SSH 1.3,1.52.0協議標準)
  8. SSH1SSH2協議中的SFTP客戶端和伺服器支援。
  9. KerberosAFS票證傳遞
  10. 資料壓縮

 

Installation of OpenSSH in Linux

To install OpenSSH, open a terminal and run the following commands with superuser permissions.

On Ubuntu/Debian/Linux Mint

$ sudo apt-get install openssh-server openssh-client

On RHEL/Centos/Fedora

Type the following yum command to install openssh client and server.

# yum -y install openssh-server openssh-clients

 

在Linux中安裝OpenSSH

要安裝OpenSSH,請開啟終端並使用超級使用者許可權執行以下命令。

在Ubuntu / Debian / Linux Mint上

$ sudo apt-get install openssh-server openssh-client

在RHEL / Centos / Fedora上

鍵入以下yum命令以安裝openssh客戶端和伺服器。

#yum -y install openssh-server openssh-clients

Configuration of OpenSSH

It’s time to configure our OpenSSH behaviour through the ssh config file, but before editing the /etc/ssh/sshd_config file we need to backup a copy of it, so in case we make any mistake we have the original copy.

Open a terminal and run the following command to make a copy of the original sshd configuration file.

$ sudo cp /etc/ssh/sshd_config  /etc/ssh/sshd_config.original_copy

As you can see from the command I typed, I added the original_copy suffix, so every time I see this file I know it is an original copy of the sshd config file.

 

配置OpenSSH

是時候通過ssh配置檔案配置我們的OpenSSH行為了,但是在編輯/ etc / ssh / sshd_config檔案之前我們需要備份它的副本,所以如果我們犯了任何錯誤,我們就有了原始副本。

開啟終端並執行以下命令以複製原始sshd配置檔案。

$ sudo cp / etc / ssh / sshd_config /etc/ssh/sshd_config.original_copy

從我輸入的命令中可以看出,我添加了original_copy字尾,所以每次看到這個檔案時我都知道它是sshd配置檔案的原始副本。

PS:保證副本這一步非常重要,因為您一旦配置錯誤了,可以用副本還原。

 

How Do I Connect to OpenSSH

Before we go further, we need to verify if our openssh server is working or not. How to do that? You can try to connect to the openssh server from your localhost through your openssh client or do a portscan with nmap, but I like to use a small tool called netcat, also known as the TCP/IPSwiss army knife. I love working with this amazing tool on my machine, so let me show it to you.

# nc -v -z 127.0.0.1 22

Referring to the netcat results, the ssh service is running on port 22 on my machine. Very good! What if we want to use another port, instead of 22? We can do that by editing the sshd configuration file.

Set your OpenSSH to listen on TCP port 13 instead of the default TCP port 22. Open the sshd_config file with your favourite text editor and change the port directive to 13.

# What ports, IPs and protocols we listen for
Port 13

Restart OpenSSH server so the changes in config file can take place by typing the following command and run netcat to verify if the port you set for listening is open or not.

$ sudo /etc/init.d/ssh restart

Should we verify is our openssh server is listening on port 13, or not?. This verification is necessary, so I am calling my lovely tool netcat to help me do the job.

# nc -v -z 127.0.0.1 13

Do you like to make your openssh server display a nice login banner? You can do it by modifying the content of /etc/issue.net file and adding the following line inside the sshd configuration file.

Banner /etc/issue.net

如何連線到OpenSSH

在我們進一步討論之前,我們需要驗證我們的openssh伺服器是否正常工作。怎麼做?您可以嘗試通過openssh客戶端localhost連線到openssh伺服器,或者使用nmap執行portscan,但我喜歡使用名為netcat的小工具,也稱為TCP / IP瑞士軍刀。我喜歡在我的機器上使用這個神奇的工具,所以讓我給你看看。

#nc -v -z 127.0.0.1 22

參考netcat結果,ssh服務在我的機器上的埠22上執行。很好!如果我們想要使用另一個埠,而不是22,該怎麼辦?我們可以通過編輯sshd配置檔案來做到這一點。

OpenSSH設定為偵聽TCP13而不是預設TCP埠22。使用您喜歡的文字編輯器開啟sshd_config檔案,並將port指令更改為13PS:常用文字編輯器:VI 、VIM 、EMACS

# What ports, IPs and protocols we listen for
Port 13

重新啟動OpenSSH伺服器,以便通過鍵入以下命令並執行netcat來驗證配置檔案中的更改是否已開啟,以驗證您設定用於偵聽的埠是否已開啟。

$ sudo /etc/init.d/ssh restart

我們應該驗證我們的openssh伺服器是否正在偵聽埠13?這個驗證是必要的,所以我打電話給我可愛的工具netcat幫助我完成這項工作。

#nc -v -z 127.0.0.1 13

你喜歡讓openssh伺服器顯示一個漂亮的登入橫幅嗎?您可以通過修改/etc/issue.net檔案的內容並在sshd配置檔案中新增以下行來完成此操作。

Banner /etc/issue.net

 

Conclusion

There are many things you can do with the openssh tools when it comes to the way you configure your openssh server, I can say that your imagination is the limit!. 

Read Also: 5 Best Practices to Secure and Protect OpenSSH Server

 

結論

在配置openssh伺服器的方式上,使用openssh工具可以做很多事情,可以說會挑戰你的想象力極限!

另請參閱:保護和保護OpenSSH伺服器的5個最佳實踐

 

轉載來源:https://www.tecmint.com/install-openssh-server-in-linux/