安装完成Debian12系统后,系统默认是没有安装SSH服务,如需要开启远程登录则需要安装相应的服务。登录系统后切换至Root用户身份并执行下面相关操作。
一、更新Debian系统数据软件源
apt-get update
二、安装SSH 服务
apt-get install -y ssh
安装完成ssh 服务默认是开启的,手动开启命令
/etc/init.d/ssh start
三、查看ssh服务状态
/etc/init.d/ssh status
执行结果:
root@debian:~# /etc/init.d/ssh status
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-03-11 10:47:15 CST; 2min 23s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1781 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1782 (sshd)
Tasks: 1 (limit: 2285)
Memory: 4.1M
CPU: 118ms
CGroup: /system.slice/ssh.service
└─1782 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
3月 11 10:47:15 debian systemd[1]: ssh.service: Found left-over process 17…ing.
3月 11 10:47:15 debian systemd[1]: This usually indicates unclean terminat…ies.
3月 11 10:47:15 debian systemd[1]: ssh.service: Found left-over process 17…ing.
3月 11 10:47:15 debian systemd[1]: This usually indicates unclean terminat…ies.
3月 11 10:47:15 debian sshd[1782]: Server listening on 0.0.0.0 port 22.
3月 11 10:47:15 debian sshd[1782]: Server listening on :: port 22.
3月 11 10:47:15 debian systemd[1]: Started OpenBSD Secure Shell server.
3月 11 10:47:23 debian sshd[1743]: Failed password for root from 172.18.18…ssh2
3月 11 10:47:31 debian sshd[1791]: Accepted password for root from 172.18.…ssh2
3月 11 10:47:31 debian sshd[1791]: pam_unix(sshd:session): session opened …d=0)
Hint: Some lines were ellipsized, use -l to show in full.
四、 安装VIM进行编辑(可选)
apt-get install -y vim
五、备份 SSH 配置文件
cp /etc/ssh/sshd_config{,.bak}
六、编辑 SSH 配置文件
利用VIM 编辑配置文件,把以下代码对 /etc/ssh/sshd_config 文件内容进行替换。
vim /etc/ssh/sshd_config
利用命令 more /etc/ssh/sshd_config |grep -v "^#" |grep -v "^$"
查看文件内容是否与下面一致,不一致则改成一致。
Include /etc/ssh/sshd_config.d/*.conf
Port 22
PermitRootLogin yes
PasswordAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
七、重启 SSH 服务
/etc/init.d/ssh restart
然后可以利用远程登录软件进行相关登录。