docker: SSH access directly into container

后端 未结 4 1124
孤城傲影
孤城傲影 2021-01-06 07:41

Up to now we use several linux users:

  • system_foo@server
  • system_bar@server
  • ...

We want to put the system users into docker cont

4条回答
  •  隐瞒了意图╮
    2021-01-06 07:49

    Some months ago, I helped my like this. It's not nice, but works. But pub-key auth needs to be used.

    Script which gets called via command in .ssh/authorized_keys

    #!/usr/bin/python
    import os
    import sys
    import subprocess
    cmd=['ssh', 'user@localhost:2222']
    if not 'SSH_ORIGINAL_COMMAND' in os.environ:
        cmd.extend(sys.argv[1:])
    else:
        cmd.append(os.environ['SSH_ORIGINAL_COMMAND'])
    sys.exit(subprocess.call(cmd))
    

    file system_foo@server: .ssh/authorized_keys

    command="/home/modwork/bin/ssh-wrapper.py" ssh-rsa AAAAB3NzaC1yc2EAAAAB...
    

    If the remote system does ssh system_foo@server the SSH-Daemon at server executes the comand given in .ssh/authorized_keys. This command does a ssh to a different ssh-daemon.

    In the docker container, there needs to run ssh-daemon which listens on port 2222.

提交回复
热议问题