1.ubuntu ssh升级到9.6
sshd_update_ubt
# 定义变量
dir="/etc/xinetd.d/"
sshd_pid=`ps -ef |grep sshd |awk '$3==1 {print $2}'`
# 结束sshd进程
stop_sshd(){
[ -z "${sshd_pid}" ] || {
kill ${sshd_pid}
}
}
# 下载telnet
apt_telnet(){
apt install -y openbsd-inetd telnetd
}
# 检查目录
check_dic(){
[ ! -d $dir ] && {
mkdir -p $dir
}
}
cfg_start_telnet(){
# telnet 配置文件
cat>/etc/xinetd.d/telnet<<'EOF'
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}
EOF
# 启动telnet
systemctl enable inetd
systemctl restart inetd
# systemctl is-enabled inetd
}
# 添加用户(telnet配置用户)
user_add(){
useradd xk3
echo "xk3:1" | chpasswd
echo 'xk3 ALL=(ALL) NOPASSWD: ALL ' >>/etc/sudoers
}
# 编译安装
make_install_new_sshd(){
# 安装依赖
apt install -y gcc zlib1g zlib1g-dev libssl-dev make
# 下载解压sshd
wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.6p1.tar.gz
tar xf openssh-9.6p1.tar.gz
cd openssh-9.6p1/
ll
# 编译安装
./configure --prefix=/app/tools/openssh-9.6p1/
nproc
make -j `nproc`
make install
# 创建软连接
ln -s /app/tools/openssh-9.6p1/ /app/tools/openssh
# 结束sshd进程
stop_sshd
}
#pkill sshd
#telnet 10.0.0.37 23 #10.0.0.5为服务器ip
#输入xk3
#和输入密码
cfg_start_new_sshd(){
# 修改新ssh配置文件
cp /app/tools/openssh/etc/sshd_config{,.bak}
cat >>/app/tools/openssh/etc/sshd_config <<EOF
Port 22
PermitRootLogin yes
PasswordAuthentication yes
#GSSAPIAuthentication no 这个不用配置,默认就关闭了.
UseDNS no
EOF
# 启动服务测试
/app/tools/openssh/sbin/sshd
# 关闭并删除openssh 8.2版本的服务端
dpkg -l |grep openssh |awk '{print $2}' |xargs dpkg --purge
# 配置PATH环境变量
echo 'export PATH=/app/tools/openssh/bin/:/app/tools/openssh/sbin/:$PATH' >>/etc/profile
source /etc/profile
#2.检查命令位置
which ssh ssh-keygen sshd
# 将sshd添加到systemctl中
useradd -s /sbin/nologin -M sshd
cat>/usr/lib/systemd/system/sshd.service<<'EOF'
[Unit]
Description=OpenSSH 9.6 server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target
[Service]
Type=simple
ExecStart=/app/tools/openssh/sbin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF
# 结束sshd进程
# pkill sshd
stop_sshd
systemctl daemon-reload
systemctl enable --now sshd
# 关闭telnet仅使用sshd
systemctl disable --now inetd
}
main(){
apt_telnet
check_dic
make_install_new_sshd
cfg_start_new_sshd
}
main
升级到openssh-9.x版本后ssh-copy-id.无法使用问题解决
ssh-copy-id.无法使用问题解决
升级到openssh-9.x版本后ssh-copy-id.无法使用问题解决
#1. 复制源码包里的ssh-copy-id命令到bin目录下
cp openssh-9.9p1/contrib/ssh-copy-id /app/tools/openssh/bin/
#2.给x权限
chmod +x /app/tools/openssh/bin/ssh-copy-id
#3.检查PATH
echo $PATH是否有 上面的bin目录
#4.测试ssh-copy-id是否可用
ssh-copy-id web01
/app/tools/openssh/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/app/tools/openssh/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/app/tools/openssh/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Authorized users only. All activities may be monitored and reported.
root@web01's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'web01'"
and check to make sure that only the key(s) you wanted were added.
#5.检查秘钥认证
ssh web01 hostname -I
Authorized users only. All activities may be monitored and reported.
10.0.0.69 172.16.1.69
标签:sshd,openssh,app,升级,ssh,Linux,copy,id From: https://www.cnblogs.com/daofaziran/p/18452442