public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Hazmi Alfarizqi <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>
Subject: [PATCH server-a001 v1 1/1] Apply default SSH config and add public keys
Date: Sat, 16 Apr 2022 00:15:54 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

1) Set the default port to 48589, don't use port 22 since we will
   inevitably get brute-force SSH attack from random botnets. Even if
   it's not really a concern if we're using a private key for the auth,
   let's not spam our auth log with many login failed lines.

2) Add maintainers' SSH public keys to the root and main user. Let us
   login from the outside world with a key auth.

Signed-off-by: Ammar Faizi <[email protected]>
---
 Dockerfile               |  16 ++++-
 etc/ssh/sshd_config      | 123 +++++++++++++++++++++++++++++++++++++++
 ssh_keys/authorized_keys |   2 +
 3 files changed, 138 insertions(+), 3 deletions(-)
 create mode 100644 etc/ssh/sshd_config
 create mode 100644 ssh_keys/authorized_keys

diff --git a/Dockerfile b/Dockerfile
index 58870ef..5e59701 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,9 +29,19 @@ RUN apt-key adv --fetch-keys https://nginx.org/keys/nginx_signing.key \
     && apt-get update \
     && apt-get -y --no-install-recommends install openssh-server nginx
 
-# Mark port 22/tcp is to be exposed
-EXPOSE 22/tcp
+# Mark port 48589/tcp is to be exposed
+EXPOSE 48589/tcp
+
+# Apply SSH config and add public keys
+COPY etc/ssh/sshd_config /etc/ssh/sshd_config
+RUN rm -rf /root/.ssh /home/${mainUser}/.ssh
+COPY ssh_keys /root/.ssh
+COPY ssh_keys /home/${mainUser}/.ssh
+RUN chown -R root:root /root/.ssh \
+    && chmod -R 600 /root/.ssh \
+    && chown -R ${mainUser}:${mainUser} /home/${mainUser}/.ssh \
+    && chmod -R 600 /home/${mainUser}/.ssh
 
 COPY docker-entrypoint.sh /
 ENTRYPOINT [ "/docker-entrypoint.sh" ]
-CMD [ "tail", "-f", "/dev/null" ]
\ No newline at end of file
+CMD [ "tail", "-f", "/dev/null" ]
diff --git a/etc/ssh/sshd_config b/etc/ssh/sshd_config
new file mode 100644
index 0000000..4cbe84f
--- /dev/null
+++ b/etc/ssh/sshd_config
@@ -0,0 +1,123 @@
+#	$OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
+
+# This is the sshd server system-wide configuration file.  See
+# sshd_config(5) for more information.
+
+# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+# The strategy used for options in the default sshd_config shipped with
+# OpenSSH is to specify options with their default value where
+# possible, but leave them commented.  Uncommented options override the
+# default value.
+
+Include /etc/ssh/sshd_config.d/*.conf
+
+Port 48589
+#AddressFamily any
+#ListenAddress 0.0.0.0
+#ListenAddress ::
+
+#HostKey /etc/ssh/ssh_host_rsa_key
+#HostKey /etc/ssh/ssh_host_ecdsa_key
+#HostKey /etc/ssh/ssh_host_ed25519_key
+
+# Ciphers and keying
+#RekeyLimit default none
+
+# Logging
+#SyslogFacility AUTH
+#LogLevel INFO
+
+# Authentication:
+
+#LoginGraceTime 2m
+PermitRootLogin prohibit-password
+#StrictModes yes
+#MaxAuthTries 6
+#MaxSessions 10
+
+#PubkeyAuthentication yes
+
+# Expect .ssh/authorized_keys2 to be disregarded by default in future.
+#AuthorizedKeysFile	.ssh/authorized_keys .ssh/authorized_keys2
+
+#AuthorizedPrincipalsFile none
+
+#AuthorizedKeysCommand none
+#AuthorizedKeysCommandUser nobody
+
+# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
+#HostbasedAuthentication no
+# Change to yes if you don't trust ~/.ssh/known_hosts for
+# HostbasedAuthentication
+#IgnoreUserKnownHosts no
+# Don't read the user's ~/.rhosts and ~/.shosts files
+#IgnoreRhosts yes
+
+# To disable tunneled clear text passwords, change to no here!
+#PasswordAuthentication yes
+#PermitEmptyPasswords no
+
+# Change to yes to enable challenge-response passwords (beware issues with
+# some PAM modules and threads)
+ChallengeResponseAuthentication no
+
+# Kerberos options
+#KerberosAuthentication no
+#KerberosOrLocalPasswd yes
+#KerberosTicketCleanup yes
+#KerberosGetAFSToken no
+
+# GSSAPI options
+#GSSAPIAuthentication no
+#GSSAPICleanupCredentials yes
+#GSSAPIStrictAcceptorCheck yes
+#GSSAPIKeyExchange no
+
+# Set this to 'yes' to enable PAM authentication, account processing,
+# and session processing. If this is enabled, PAM authentication will
+# be allowed through the ChallengeResponseAuthentication and
+# PasswordAuthentication.  Depending on your PAM configuration,
+# PAM authentication via ChallengeResponseAuthentication may bypass
+# the setting of "PermitRootLogin without-password".
+# If you just want the PAM account and session checks to run without
+# PAM authentication, then enable this but set PasswordAuthentication
+# and ChallengeResponseAuthentication to 'no'.
+UsePAM yes
+
+#AllowAgentForwarding yes
+#AllowTcpForwarding yes
+#GatewayPorts no
+X11Forwarding yes
+#X11DisplayOffset 10
+#X11UseLocalhost yes
+#PermitTTY yes
+PrintMotd no
+#PrintLastLog yes
+#TCPKeepAlive yes
+#PermitUserEnvironment no
+#Compression delayed
+ClientAliveInterval 15
+#ClientAliveCountMax 3
+#UseDNS no
+#PidFile /var/run/sshd.pid
+#MaxStartups 10:30:100
+#PermitTunnel no
+#ChrootDirectory none
+#VersionAddendum none
+
+# no default banner path
+#Banner none
+
+# Allow client to pass locale environment variables
+AcceptEnv LANG LC_*
+
+# override default of no subsystems
+Subsystem	sftp	/usr/lib/openssh/sftp-server
+
+# Example of overriding settings on a per-user basis
+#Match User anoncvs
+#	X11Forwarding no
+#	AllowTcpForwarding no
+#	PermitTTY no
+#	ForceCommand cvs server
diff --git a/ssh_keys/authorized_keys b/ssh_keys/authorized_keys
new file mode 100644
index 0000000..6465aa5
--- /dev/null
+++ b/ssh_keys/authorized_keys
@@ -0,0 +1,2 @@
+ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK4MbVLR2847dHKdtr4M0p9g3M1Q9eiv4Lhr1x1x6RJ1 [email protected]
+ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKhFfg8XTsIp3KM93LeLxOPtR/fGozCgtND9ySLbMUSA [email protected]
-- 
Ammar Faizi


  reply	other threads:[~2022-04-15 17:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 17:15 [PATCH server-a001 v1 0/1] Apply default SSH config and add public keys Ammar Faizi
2022-04-15 17:15 ` Ammar Faizi [this message]
2022-04-15 17:29   ` [PATCH server-a001 v1 1/1] " Alviro Iskandar Setiawan
2022-04-15 17:36     ` Ammar Faizi
2022-04-15 17:33   ` Alviro Iskandar Setiawan
2022-04-15 17:37     ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox