Skip to content

Commit fc672eb

Browse files
committed
Added documentation for preferred alternative to SSH for container access.
1 parent 7c55701 commit fc672eb

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Included in the build is the EPEL repository and SSH, vi and are installed along
1111

1212
SSH access is by public key authentication and, by default, the [Vagrant](http://www.vagrantup.com/) [insecure private key](https://github.com/mitchellh/vagrant/blob/master/keys/vagrant) is required.
1313

14+
SSH is not required in order to access a terminal for the running container the prefered method is to use Command Keys and the nsenter command. See [command-keys.md](https://github.com/jdeathe/centos-ssh/blob/centos-6/command-keys.md) for details on how to set this up.
15+
1416
## Quick Example
1517

1618
Run up a container named 'ssh.pool-1.1.1' from the docker image 'jdeathe/centos-ssh' on port 2020 of your docker host.

command-keys.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Command Keys
2+
3+
Using command keys to access containers (without sshd).
4+
5+
Access docker containers using docker host SSH public key authentication and nsenter command to start up a bash terminal inside a container. In the following example the container name is "ssh.pool-1.1.1"
6+
7+
## Create a unique public/private key pair for each container
8+
9+
```
10+
$ cd ~/.ssh/ && ssh-keygen -q -t rsa -f id-rsa.ssh.pool-1.1.1
11+
```
12+
13+
## Prefix the public key with the nsenter command
14+
15+
```
16+
$ sed -i '' \
17+
'1s#^#command="sudo nsenter -m -u -i -n -p -t $(docker inspect --format \\\"{{ .State.Pid }}\\\" ssh.pool-1.1.1) /bin/bash" #' \
18+
~/.ssh/id-rsa.ssh.pool-1.1.1.pub
19+
```
20+
21+
## Upload the public key to the docker host VM
22+
23+
The host in this example is core-01.local that has SSH public key authentication enabled using the Vagrant insecure private key.
24+
25+
### Generic Linux Host Example
26+
27+
```
28+
$ cat ~/.ssh/id-rsa.ssh.pool-1.1.1.pub | ssh -i ~/.vagrant.d/insecure_private_key \
29+
30+
"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
31+
```
32+
33+
### CoreOS Host Example
34+
35+
```
36+
$ cat ~/.ssh/id-rsa.ssh.pool-1.1.1.pub | ssh -i ~/.vagrant.d/insecure_private_key \
37+
38+
update-ssh-keys -a [email protected]
39+
```
40+
41+
### Usage
42+
43+
```
44+
$ ssh -i ~/.ssh/id-rsa.ssh.pool-1.1.1 \
45+
46+
-o StrictHostKeyChecking=no
47+
```
48+
49+
#### SSH Config
50+
51+
To simplify the command required to access the running container we can add an entry to the SSH configuration file ```~/.ssh/config``` as follows:
52+
53+
```
54+
Host core-01.ssh.pool-1.1.1
55+
HostName core-01.local
56+
Port 22
57+
User core
58+
StrictHostKeyChecking no
59+
IdentitiesOnly yes
60+
IdentityFile ~/.ssh/id-rsa.ssh.pool-1.1.1
61+
```
62+
63+
With the above entry in place we can now run the following to access the running container:
64+
65+
```
66+
$ ssh core-01.ssh.pool-1.1.1
67+
```

0 commit comments

Comments
 (0)