centos7
shell
yum -y install gcc zlib-devel perl
cd /tmp/ && tar -xvf /tmp/openssh-8.6p1.tar.gz
mkdir /tmp/bak
cp -r /etc/ssh /tmp/bak/ssh
cp -r /etc/pam.d /tmp/bak/pam.d
cp -r /usr/bin/ssh /tmp/bak/ssh
cd /tmp/openssh-8.6p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
make && make install
rpm -qa | grep openssh | xargs rpm -e
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp -a /tmp/openssh-8.6p1/contrib/redhat/sshd.init /etc/init.d/sshd
cp -a /tmp/openssh-8.6p1/contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod +x /etc/init.d/sshd
cp /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
sed -i "s/\#PermitRootLogin/PermitRootLogin/" /etc/ssh/sshd_config
sed -i "s/libexec\/openssh/local\/openssh\/libexec/" /etc/ssh/sshd_config
systemctl enable sshd
/etc/init.d/sshd restart
ubuntu1804
shell
apt-get install -y gcc zlib1g-dev perl make
cd /tmp/ && tar -xvf /tmp/openssh-8.6p1.tar.gz
cd /tmp/openssh-8.6p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
make && make install
apt-get remove -y openssh-client openssh-server
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
sed -i "s/libexec\/openssh/local\/openssh\/libexec/" /etc/ssh/sshd_config
systemctl unmask ssh
systemctl enable ssh
systemctl restart ssh
注意
需要修改/etc/ssh/sshd_config配置文件,sftp才可用。
bash
Subsystem sftp /usr/libexec/openssh/sftp-server
# 改为
Subsystem sftp /usr/local/openssh/libexec/sftp-server