centos
创建容器
docker run -itd --privileged=true -p 22002:22 --name test_sftp centos
#-itd 以交互模式在后台运行
#--privileged=true 使root拥有真正的root权限
#-p 端口映射
#--name 容器定义名字
进入容器
docker exec -it test_sftp bash
安装passwd,openssl,openssh-server
yum install passwd openssl openssh-server -y
启动sshd
/usr/sbin/sshd -D
这时可能会有以下错误:
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
执行以下命令解决:
ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''
执行命令修改 /etc/ssh/sshd_config 配置信息:
sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config
sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config
重新启动sshd
/usr/sbin/sshd -D
修改root密码,然后就可以用sftp连接到容器了
passwd root
ubuntu
更新apt-get
apt-get update
下载vim
apt-get install vim
修改root密码
passwd root
安装ssh
apt-get install openssh-server openssl
查看状态
service ssh status
开启ssh
service ssh start
配置ssh,运行root登录
vim /etc/ssh/sshd_config
PermitRootLogin的值从prohibit-password改为yes
vim /etc/ssh/sshd_config
PermitRootLogin的值从prohibit-password改为yes
PermitRootLogin prohibit-password -> PermitRootLogin yes
重启ssh
service ssh restart