docker的centos如何啟動sshd服務__docker

來源:互聯網
上載者:User

先啟動一個純的centos容器

docker run -it --name=sample centos /bin/bash

然後打ssh localhost會發現如下錯誤。

bash: ssh: command not found

接下去就教你如何能夠ssh localhost.

yum install openssh-serveryum install openssh-clients

這時候再試一下ssh localhost,發現錯誤改變:
ssh: connect to host localhost port 22: Cannot assign requested address

說明sshd服務還沒有開啟。用ps -ef也可以驗證這一點。

由於是docker裡面的centos,所以service和systemctl都不好用。

嘗試手動運行/usr/sbin/sshd

報如下錯誤:

Could not load host key: /etc/ssh/ssh_host_rsa_keyCould not load host key: /etc/ssh/ssh_host_ecdsa_keyCould not load host key: /etc/ssh/ssh_host_ed25519_keysshd: no hostkeys available -- exiting.

手動執行/usr/sbin/sshd-keygen -A

再執行/usr/sbin/sshd成功。

為了免密碼本機跳本機,執行如下命令:

ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsacat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keyschmod 0600 ~/.ssh/authorized_keys

至此,執行ssh localhost就能成功。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.