Yes, there is a private key available in the app container environment: the diego-sshd
SSH server process running inside the app container has its own private key stored in its environment as the SSHD_HOSTKEY
environment variable.
Once you've used cf ssh
to get a shell session inside the app container, here's a quick way to extract that PEM-encoded private key value to a file and then to use it to authenticate to the diego-sshd
server:
$ strings /proc/$(pidof diego-sshd)/environ | awk '/-----BEGIN/,/-----END/' | sed 's/SSHD_HOSTKEY=//g' > sshdkey
$ chmod 0600 sshdkey
$ ssh -i sshdkey -p 2222 localhost
You need the chmod
command to restrict permissions on the private key file to only the vcap
user in the app container, as otherwise the SSH client will complain that permissions are too open.
It's hard to tell that you've done anything once you start that SSH session, as the shell prompt will look identical to the existing CF SSH session, but you can check by tracing your shell's PID through the process tree:
$ pstree -pT $(pidof diego-sshd)
diego-sshd(8)───bash(259)───pstree(323)
$ echo $$
259
$ ssh -i sshdkey -p 2222 localhost
$ pstree -pT $(pidof diego-sshd)
diego-sshd(8)─┬─bash(259)───ssh(341)
└─bash(342)───pstree(353)
$ echo $$
342
In this case,
259
is the PID of the bash
process started by the initial CF SSH session,
341
is the PID of the ssh
process starting the nested SSH session,
342
is the PID of the bash
process started by that client's session.
Some background on what's going on with the CF internals: