Post

New VM - Container SSH script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# New server setup
sudo apt-get update
sudo apt-get install openssh-server -y

# Configure SSH options
sudo sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 600/' /etc/ssh/sshd_config
sudo sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/' /etc/ssh/sshd_config
sudo sed -i 's/#PermitRootLogin yes/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config

# Your public keys
keys="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDUd55+PJVVPThXEoYBkmpYNs+l/wubKXPgnQe5WutboHArmecfZjfcdQGSBvLczWL7KVo0Gp0e664rmsAUCGI925o5BgEbC8c71Q/jZBxzatsfRqqE7xWHc0jkOEi8nIiWV2abtyZ05doe89qtppAAS3x9tXhixCzSE+9KXMv6C0b8xLin7kLlnJvP5sUrh1wjfKwDjufWBXX9DDNqUzltUzRInfpnCWScH+6FOgaMR5e+0xIkTpcACwfGRRoxMPauWjpNHQJbRQF02yYA6UEjH23Q7gnpbBvse1uAGwKEmPwtUu576/pTsmi5pGquH8F6/GM2QJldwrVaUhne01YYkUlIbON8luhIp0fnsoCNtqvKHzsejA2M83LMZMMDXTJI7PdXpBP6KdmwGuMvW8duLbi6qIixS37GpA98ZppJ9h3YcfVq3eY8oPwIHdt4/nDSuBd1DGqQNqGLGA4hm9potTWTFS/5VUEybLvUVyi5ZRyasyi9S9a4qB6dyx0kghM=
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3NOoulZ0zfS4bcKptRHYpt51E5p32XIhCxKuYp0CDkRbqAhF2EhQRHKGNvNO3Q5a9dorqdE6/+/LxvE8p9cT9GRLtP/P74Mx0C++9Oxe834sk6kJ5jcHhu1kJKQtSh4IEfcoEZxEwFnUqv+WpvRY+OB19KBsNnsCVT3tsPggFbPh874nAnh6Y1TM0FKsCfoJsrNt+Nep+MRtMZ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~/.ssh/authorized_keys
# Add your public keys to authorized_keys
echo "$keys" | sudo tee -a /root/.ssh/authorized_keys

# Set permissions and ownership for authorized_keys
sudo chmod 600 /root/.ssh/authorized_keys
sudo chown root:root /root/.ssh/authorized_keys

# Disable login message
sudo chmod -x /etc/update-motd.d/*
sudo service ssh restart
# touch ~/.bashrc
# theme = "export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\$ "
# echo "$theme" | sudo tee -a ~/.bashrc

# Restart SSH service
sudo service ssh restart
This post is licensed under CC BY 4.0 by the author.