openssh RPM包制作
1.#依賴安裝
yum install rpm-build gcc make wget openssl-devel krb5-devel pam-devel libX11-devel xmkmf libXt-devel initscripts
2.#目錄創建
mkdir -p /usr/src/redhat/{SOURCES,SPECS}
cd /usr/src/redhat/SOURCES/
3.#安裝文件下載
wget https://mirrors.evowise.com/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
4.#解壓編譯文件,或者直接自己寫
cd /usr/src/redhat/SOURCES/
# 也可以解壓出整包 從裏面提取出 openssh-7.5p1/contrib/redhat/openssh.spec 該文件
tar xf openssh-7.9p1.tar.gz openssh-7.9p1/contrib/redhat/openssh.spec
chown sshd:sshd /usr/src/redhat/SPECS/openssh.spec
cp /usr/src/redhat/SPECS/openssh.spec /usr/src/redhat/SPECS/openssh.spec_def
-
修改幾個配置選項 可選項
#關掉no_gnome_askpass no_x11_askpass這兩個參數
sed -i -e "s/%define no_gnome_askpass 0/%define no_gnome_askpass 1/g" /usr/src/redhat/SPECS/openssh.spec
#實際編譯參數:(spec文件裏有註明)
- ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc/ssh --libexecdir=/usr/libexec/openssh --datadir=/usr/share/openssh --with-default-path=/usr/local/bin:/bin:/usr/bin --with-superuser-path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin --with-privsep-path=/var/empty/sshd --with-md5-passwords --with-tcp-wrappers --with-pam --with-kerberos5=/usr
configure: WARNING: unrecognized options: --with-tcp-wrappers
#可以用這個命令查看編譯文件裏面的參數值 /usr/src/redhat/SPECS/openssh.spec
#rpm --eval "%{?dist}"
#rpm --eval "%{?ver}"
#很多是在文件裏設置的初值,部分是在系統文件裏定義的,系統默認的變量定義在這個文件 #vim /usr/lib/rpm/macros
#我只修改了這2行
vim openssh.spec
%define no_x11_askpass 0
%define no_gnome_askpass 0
- 拷貝安裝軟件到預編譯目錄
mkdir -p ~/rpmbuild/SOURCES/
cp /usr/src/redhat/SOURCES/openssh-7.9p1.tar.gz ~/rpmbuild/SOURCES/
cp /usr/src/redhate/SOURCES/x11-ssh-askpass-1.2.4.1.tar.gz ~/rpmbuild/SOURCES/
#執行編譯操作
cd /usr/src/redhat/SPECS/
rpmbuild -ba openssh.spec
##############################################################
#安裝包的目錄如下
ll /root/rpmbuild/RPMS/x86_64/openssh-*
-rw-r--r-- 1 root root 484024 12月 21 10:41 openssh-7.9p1-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 625176 12月 21 10:41 openssh-clients-7.9p1-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 3006728 12月 21 10:41 openssh-debuginfo-7.9p1-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 393156 12月 21 10:41 openssh-server-7.9p1-1.el6.x86_64.rpm
##############################################################
#備份原有的openssh服務
mkdir -p /backup/openssh_def
cd /backup/openssh_def
tar cvzf etc_ssh.tar.gz /etc/ssh
cp /etc/pam.d/sshd /etc/pam.d/system-auth .
cp -p /etc/pam.d/sshd /etc/pam.d/sshddate +%Y%m%d
cp -p /etc/pam.d/system-auth /etc/pam.d/system-authdate +%Y%m%d
cp -p /etc/ssh/sshdconfig .
cp -p /etc/ssh/sshconfig .
#執行升級操作
rpm -Uvh /root/rpmbuild/RPMS/x86_64/*.rpm
把新的 /etc/pam.d/sshd文件備份,並恢復原來版本的 /etc/pam.d/sshd
cp -p /etc/pam.d/sshd /root/sshd.afterupgrade
cp /root/sshd.orig /etc/pam.d/sshd
- 開啟PAM
vi /etc/ssh/sshd_config
UsePAM yes - 重啟sshd服務
#CentOS 6
service sshd restart
#CentOS 7
#systemctl restart sshd
##########################################################################
升級後出現的錯誤及解決方案:
-
重啟報錯或者ssh無法登錄"no hostkey alg"
rm -r /etc/ssh/ssh*key
systemctl restart sshd
#或者重新生成ssh主機密鑰
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -
啟動sshd正常,但登錄時出現密碼驗證錯誤,但密碼實際是正確的
這種情況一般是 /etc/pam.d/sshd文件問題,恢復之前備份即可 - 用xshell之類的工具ssh登錄,報錯:
這種報錯生成ssh主機密鑰解決(參考1 重啟報錯或者ssh無法登錄"no hostkey alg")
openssh RPM包制作