Skip to content

Commit

Permalink
use sudo to execute command (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
shunk031 authored May 12, 2024
1 parent b91de72 commit a55434c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions install/ubuntu/server/setup_timezone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fi

function main() {
export TZ="Asia/Tokyo"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
echo $TZ > /etc/timezone
sudo ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
echo "${TZ}" | sudo tee /etc/timezone

DEBIAN_FRONTEND="noninteractive" apt-get install -y tzdata
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y tzdata
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
Expand Down
26 changes: 14 additions & 12 deletions install/ubuntu/server/ssh_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ if [ "${DOTFILES_DEBUG:-}" ]; then
fi

function install_openssh_server() {
# install openssh-server
apt-get update && apt-get install --no-install-recommends -y vim openssh-server
# install openssh-server and vim
sudo apt-get update && sudo apt-get install --no-install-recommends -y \
vim \
openssh-server
}

function setup_sshd() {
mkdir -p /var/run/sshd
mkdir -p /root/.ssh
sudo mkdir -p /var/run/sshd
mkdir -p ${HOME}/.ssh

sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config &&
sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config &&
sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config &&
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config &&
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
sudo sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config &&
sudo sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config &&
sudo sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config &&
sudo sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config &&
sudo sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# check the /etc/ssh/sshd_config
/usr/sbin/sshd -t
sudo /usr/sbin/sshd -t

# create .ssh/authorized_keys if not exists
touch ~/.ssh/authorized_keys
touch ${HOME}/.ssh/authorized_keys
}

function run_sshd() {
# run sshd
/usr/sbin/sshd
sudo /usr/sbin/service ssh start
}

function main() {
Expand Down

0 comments on commit a55434c

Please sign in to comment.