-
Notifications
You must be signed in to change notification settings - Fork 1
/
initvm.sh
79 lines (67 loc) · 2.08 KB
/
initvm.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
set -e -x
# Check prerequisites.
[ -z "$hostname" ] && echo "error: hostname not set" >&2 && exit 1
[ -z "$username" ] && echo "error: username not set" >&2 && exit 1
[ -z "$userpass" ] && echo "error: userpass not set" >&2 && exit 1
[ ! -r /tmp/key*.txt ] && echo "error: keys missing" >&2 && exit 1
# Add user.
adduser "$username" --gecos '' --disabled-password
echo "$username:$userpass" | chpasswd
adduser "$username" sudo
# Copy SSH keys.
umask 077
mkdir -p /home/$username/.ssh
cat /tmp/key*.txt >> /home/$username/.ssh/authorized_keys
chown -R $username:$username /home/$username/.ssh
# Disable root login.
passwd -d root
passwd -l root
# Disable SSH root login and SSH password login.
sed -i 's/^PermitRootLogin/#PermitRootLogin/' /etc/ssh/sshd_config
sed -i 's/^PasswordAuthentication/#PasswordAuthentication/' /etc/ssh/sshd_config
echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
systemctl restart ssh
# Install minimal set of tools.
apt-get update
apt-get -y install git make tree rsync
# Set timezone.
rm -f /etc/localtime
echo Asia/Kolkata > /etc/timezone
sudo dpkg-reconfigure -f noninteractive tzdata
# Set hostname.
echo "$hostname" > /etc/hostname
echo 127.0.0.1 "$hostname" >> /etc/hosts
# Configure Git.
git config --system user.name "Sunaina Pai"
git config --system user.email "[email protected]"
# Set default editor.
update-alternatives --set editor /usr/bin/vim.basic
# Configure Vim.
cat > /etc/vim/vimrc.local <<eof
syntax on
colorscheme murphy
set textwidth=72
set tabstop=4
set shiftwidth=0
set expandtab
set autoindent
set guioptions=i
set number
set hlsearch
set showcmd
set hidden
set ruler
set autochdir
set nojoinspaces
set modeline
set wildmenu
set listchars=eol:$,tab:>-,nbsp:~,trail:~
autocmd BufNewFile,BufRead *.md,*.txt set filetype=markdown
autocmd BufNewFile,BufRead *.html,*.css,*.js,*.json,*.yml,*.yaml set tabstop=2
autocmd BufNewFile,BufRead *.go,Makefile setlocal tabstop=8 noexpandtab
autocmd BufWinEnter * syntax keyword Todo TODO
autocmd BufWinEnter * syntax match Error /\s\+$/
eof
# Reboot.
reboot