Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
如何编译安装最新的OpenSSH(How to build OpenSSH)
Experiences and Insight
1073
views ·
0
replies ·
To
floor
Go
deepinuser17
deepin
2019-11-14 19:41
Author
本帖最后由 deepinuser17 于 2019-11-27 09:00 编辑
如果想安装最新的OpenSSH, 而添加软件源又比较麻烦,可以下载OpenSSH的源文件包,自己编译安装. 目前最新的版本是8.1p1. 这样做的好处是不影响系统安装的OpenSSH, 而且很容易转回系统的OpenSSH.
以下的步骤已经在Deepin 15.11上验证安装成功.
1. 安装编译所需要的软件包
sudo apt -y install dirmngr
sudo apt -y install libpam0g-dev
sudo apt -y install libssl-dev
Copy the Code
2. 下载最新的OpenSSH源文件包,并验证.下载地址在网页里:
https://www.openssh.com/portable.html
cd /tmp
wget https://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-8.1p1.tar.gz
wget https://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-8.1p1.tar.gz.asc
验证下载的软件包:
gpg --verify openssh-8.1p1.tar.gz.asc openssh-8.1p1.tar.gz
gpg --receive-keys 59C2118ED206D927E667EBE3D3E5F56B6D920D30
gpg --verify openssh-8.1p1.tar.gz.asc openssh-8.1p1.tar.gz
成功验证的结果如下:
gpg: Signature made Tue 08 Oct 2019 05:39:36 PM PDT
gpg: using RSA key 59C2118ED206D927E667EBE3D3E5F56B6D920D30
gpg: Good signature from "Damien Miller " [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 59C2 118E D206 D927 E667 EBE3 D3E5 F56B 6D92 0D30
Copy the Code
3. 编译OpenSSH
cd /tmp
tar -zxvf openssh-8.1p1.tar.gz
cd openssh-8.1p1
./configure --prefix=/usr/local/openssh-8.1p1 \
--sysconfdir=/etc/ssh \
--with-pam \
--with-md5-passwords \
--with-prngd-socket=/dev/random \
--with-ssl-dir=/usr/lib/x86_64-linux-gnu \
--with-zlib
make -j2
sudo make install
sudo ln -s /usr/local/openssh-8.1p1 /usr/local/openssh
Copy the Code
4. 设置sshd启动文件
sudo cp /usr/lib/systemd/system/ssh.service /etc/systemd/system/
Copy the Code
修改/etc/systemd/system/ssh.service 如下:
[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.services
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/local/openssh/sbin/sshd -t
ExecStart=/usr/local/openssh/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/local/openssh/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target
Alias=sshd.service
Copy the Code
重启sshd服务:
sudo systemctl stop sshd
sudo systemctl daemon-reload
sudo systemctl start sshd
Copy the Code
注意:
用户创建,修改的启动文件应当保存在/etc/systemd/system文件夹里.不要修改在/usr/lib/systemd/system/里的文件.这些文件是由操作系统管理的.在更新软件时,/usr/lib/systemd/system/里的文件可能会被修改.如果需要改动,从/usr/lib/systemd/system的启动文件复制一份到/etc/systemd/system,然后再修改/etc/systemd/system里的文件.有同名的启动文件时,systemd会执行/etc/systemd/system里的启动文件,而非/usr/lib/systemd/system的同名启动文件.
5. 测试
从另外一个机器通过ssh连接已更新OpenSSH的机器.
在更新OpenSSH的机器上,如果想使用新版OpenSSH客户端,可以运行:
/usr/local/openssh/bin/ssh <用户名>@<远程机器名或ip地址>
Copy the Code
如果不想使用全路径(只用ssh命令),或是把最新的OpenSSH设为默认版本,可以设路径环境变量,并加到/home/<用户名>/.bashrc的最后面:
# Custom setting
PATH=/usr/local/openssh/bin:$PATH
export PATH
Copy the Code
如果不重新登录,运行以下命令更新环境变量:
source ~/.bashrc
或:
.~/.bashrc
Copy the Code
检验:
$ which ssh
/usr/local/openssh/bin/ssh
$ ssh -V
OpenSSH_8.1p1, OpenSSL 1.1.0j 20 Nov 2018
Copy the Code
Reply
Like 0
Favorite
View the author
All Replies
No replies yet
Please
sign
in first
Featured Collection
Change
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
WiFi Drivers
Popular Events
More
如果想安装最新的OpenSSH, 而添加软件源又比较麻烦,可以下载OpenSSH的源文件包,自己编译安装. 目前最新的版本是8.1p1. 这样做的好处是不影响系统安装的OpenSSH, 而且很容易转回系统的OpenSSH.
以下的步骤已经在Deepin 15.11上验证安装成功.
1. 安装编译所需要的软件包
2. 下载最新的OpenSSH源文件包,并验证.下载地址在网页里: https://www.openssh.com/portable.html
5. 测试
从另外一个机器通过ssh连接已更新OpenSSH的机器.
在更新OpenSSH的机器上,如果想使用新版OpenSSH客户端,可以运行: