Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ssh connection in docker virtual machine

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use ssh connection in docker virtual machine". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, install docker

Instead of demonstrating how to install it, there are many tutorials online.

II. Concrete steps

1. Pull centos image

Docker pull centos:centos7

2. View / start the image

# View image docker images# boot image docker run-itd-- name my-centos centos:centos7

3. Enter the mirror image

# get the iddocker ps# of the container and enter the docker exec-it 9bd5d8e8a3e7 / bin/bash inside the container

4. Install software for the container

# install sshyum install-y openssh-server openssh-clients# change password command yum install-y passwd#service command yum install-y initscripts

5. Change the password

# change password command passwd

6. Modify sshd_config configuration file

# modify the file vi / etc/ssh/sshd_config# to find the UsePAM parameter and set it to no

7. Restart ssh and exit the container

# restart sshservice sshd start# and error System has not been booted with systemd as init system (PID 1) will be reported here. Can't operate.Failed to connect to bus: Host is down# just issue the following command directly. Using the command in the last step to start will solve this problem # exit container exit

8. Save the newly modified container as a new image

Docker commit 9bd5d8e8a3e7 my-ssh-centos

9. Start a new image

# Note to expose the externally mapped port-privileged=true and the subsequent / sbin/init must be available, and start the container in privileged mode, otherwise you cannot start the service docker run-tid-- name my-ssh-0-p 50022systemctl 22-- privileged=true 9bd5d8e8a3e7 / sbin/init "how to use ssh connection in the docker virtual machine". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report