Centos容器内无需使用systemctl启动sshd的方法

在Docker容器中启用systemctl命令失败后,通过安装sshd,生成ssh密钥,修改sshd_config允许root登录和密码认证,然后重启sshd服务来解决问题。确认sshd在22端口监听。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

新建docker容器时,在参数中添加了--privileged=true,但是依然无法使用systemctl命令,系统提示Operation not permitted

解决

首先确保容器内安装了sshd

yum install -y openssh-server

ecdsa加密方式生成ssh密钥

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -P '' -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -P '' -f /etc/ssh/ssh_host_ed25519_key

生成密钥之后,修改sshd_config

vim /etc/ssh/sshd_config
# 修改以下参数
PermitRootLogin yes
PasswordAuthentication yes

修改完成之后,重启sshd

/usr/sbin/sshd -f /etc/ssh/sshd_config

查看端口监听状态

netstat -anp | grep 22
# tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      201/sshd            
# tcp6       0      0 :::22                   :::*                    LISTEN      201/sshd  

启动成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值