1、系统环境介绍
1.1 系统版本
debian-9.6.0-amd64-netinst
1.2 系统内核
Linux lnnkee 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux
2、安装编译环境
apt install -y gcc g++ libssl-dev build-essential libtool automake zlib*
3、下载安装包
wget https://cdn.openbsd.org./pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
4、配置安装环境
4.1 配置sshd权限
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin #修改/etc/passwd文件,在其中加入即可
4.2 创建安装目录
mkdir /usr/local/ssh
5、编译安装openssh
mkdir /usr/local/ssh tar xvf openssh-7.9p1.tar.gz ./configure --prefix=/usr/local/ssh --sysconfdir=/usr/local/ssh make && make install
6、配置文件说明
6.1 启动sshd服务
/usr/local/ssh/sbin/sshd #启动SSH运行服务
6.2 配置root访问登陆
PermitRootLogin yes #配置文件为/usr/local/ssh/etc/sshd_config,配置此条目为允许root登陆
7、配置systemctl启动脚本
7.1 配置sshd服务启动脚本
sshd.service服务存放位置为/lib/systemd/system/sshd.service,
之后,新建软连接,ln -s /lib/systemd/system/sshd.service /etc/systemd/system/sshd.target.wants/
sshd.service配置文件如下:
#[Unit]部分主要是对这个服务的说明,内容包括Description和After,Description#用于描述服务,After用于描述服务类别 [Unit] Description=ssh system After= #[Service]部分是服务的关键,是服务的一些具体运行参数的设置,这里Type=forking #是后台运行的形式,PIDFile为存放PID的文件路径,ExecStart为服务的具体运行命令, #ExecReload为重启命令,ExecStop为停止命令,PrivateTmp=True表示给服务分配独 #立的临时空间,注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使 #用相对路径则会报错! [Service] Type=simple PIDFile=/var/run/sshd.pid ExecStart=/usr/local/ssh/sbin/sshd ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true #[Install]部分是服务安装的相关设置,可设置为多用户的 [Install] WantedBy=multi-user.target
7.2 配置开机启动
systemctl enable sshd.service #使某服务自动启动 systemctl disable sshd.service #使某服务不自动启动 systemctl status sshd.service #检查服务状态
8、参考资料
#配置sshd.service启动脚本
#解决Type=simple或forking
https://www.cnblogs.com/zdz8207/p/linux-systemctl.html # systemctl配置开机启动