forked from metaphysix/Bacula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSH_Gen
51 lines (35 loc) · 1.1 KB
/
SSH_Gen
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
#! /bin/bash
###################################################
### OpenSSH Server initial configuration script ###
###################################################
# Определяем переменные
SSH_CONF_DIR='/etc/ssh'
SSH_CONF_FILE='/etc/ssh/sshd_config'
SSH_CONF_FILE_OLD='/etc/ssh/sshd_config.old'
SSH_KEY_FILE='~/.ssh/id_rsa'
# Резервируем конфигурационный файл
if [ -d "$SSH_CONF_DIR" ]; then
echo 'Backing up configuration file...'
cp ${SSH_CONF_FILE} ${SSH_CONF_FILE_OLD} && \
echo 'Done!'
else
echo 'OpenSSH Server directory non exist!'
exit 1
fi
# Генерируем приватный и публичный ключ
echo 'Generating SSH keys...'
ssh-keygen -b 4096 -f ${SSH_KEY_FILE} -N 'gnuisnotunix' >> /dev/null && \
echo 'Done!'
sleep 2
# Подготавливаем ключи
if [ -f "$SSH_KEY_FILE" ]; then
echo 'Creating autohorized keys file...'
mv ${SSH_KEY_FILE} ~/.ssh/authorized_keys && \
echo 'Done!'
else
echo 'SSH key not exist!'
exit 1
fi
sleep 1
echo 'Changing permissions..'
chmod -R 700 ${SSH_KEY_DIR} && echo 'Done!'