Skip to content

Commit 4f708fb

Browse files
committed
Allow to have no imported SSH keys in the image
1 parent 7032d3d commit 4f708fb

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

docker/entrypoint.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
# Enable strict mode (exit on error).
44
set -e
55

6-
# Copy all ssh keys to the home directory, as the temporary directory will be
7-
# cleared within seconds afters starting the container.
8-
cp -R /tmp/.ssh/* /root/.ssh/
6+
# The /tmp/.ssh directory is used to pass SSH keys to the container. If it is empty
7+
# or does not exist, no SSH keys will be imported.
8+
if [ -d "/tmp/.ssh" ] && [ "$(ls -A /tmp/.ssh 2>/dev/null)" ]; then
99

10-
# Ensure proper line breaks and line endings in all SSH key files.
11-
find /root/.ssh -type f -name "id_*" -exec dos2unix -q {} +
10+
# Copy all SSH keys from the temporary directory to the root's SSH directory.
11+
cp -R /tmp/.ssh/* /root/.ssh/
1212

13-
# Set the required permissions for SSH key files.
14-
chmod 700 /root/.ssh
15-
find /root/.ssh/ -type f -name "id_*" -exec chmod 600 {} +
16-
find /root/.ssh/ -type f -name "id_*.pub" -exec chmod 644 {} +
13+
# Ensure proper line breaks and line endings in all SSH key files.
14+
find /root/.ssh -type f -name "id_*" -exec dos2unix -q {} +
15+
16+
# Set the required permissions for SSH key files.
17+
find /root/.ssh/ -type f -name "id_*" -exec chmod 600 {} +
18+
find /root/.ssh/ -type f -name "id_*.pub" -exec chmod 644 {} +
1719

18-
# Start the ssh agent and add the keys to the current session.
19-
eval "$(ssh-agent)" > /dev/null
20-
find /root/.ssh -type f -name "id_*" ! -name "*.pub" -exec ssh-add -q {} \;
20+
# Start the ssh agent and add the keys to the current session.
21+
eval "$(ssh-agent)" > /dev/null
22+
find /root/.ssh -type f -name "id_*" ! -name "*.pub" -exec ssh-add -q {} \;
23+
fi
24+
25+
# Set the required permissions for the SSH directory.
26+
chmod 700 /root/.ssh
2127

2228
# Execute the command passed as arguments.
2329
exec "$@"

0 commit comments

Comments
 (0)