SetupCentOS7.5

1.Let’s setup CentOS7.5 server. Contains : ssh login,Promp, Partition, General user account

1.Setup Auto SnapShot of disk

2.Set SSH key login

2.1.Add id_rsa.pub SSH Key on cloud Control

2.2.Add correct host key in user/.ssh/known_hosts

1
2
3
4
ssh-keygen -R xxx.xxx.xxx.xxx
#/.ssh/known_hosts updated.
#Are you sure you want to continue connecting (yes/no)? yes
ssh root@xxx.xxx.xxx.xxx

2.3. Disable passwd login

1
2
3
vi /etc/ssh/sshd_config
PasswordAuthentication no
service sshd restart

3.4.Changed ip for domain may cause error

1
2
3
4
5
#The ECDSA host key for www.heavenyu.com has changed,
#and the key for the corresponding IP address 106.12.110.178
#is unchanged.
vi ~/.ssh/known_hosts
#change the key for domain manualy

3.Terminal

3.1.Set Promp

1
vi .bashrc

add

1
2
export PS1='[\t \W]\$'
alias vi='vim'

to the end of the ~/.bashrc

1
source .bashrc

we got this prompt:

1
[22:40:00 ~]#

3.2.Vim

1
2
3
4
5
6
vi /etc/vimrc
#add
:set number
set tabstop=4
set expandtab
set shiftwidth=4

4.Partition

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
fdisk -l
fdisk /dev/vdb

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): 50000000
Partition 1 of type Linux and of size 23.9 GiB is set

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (50000001-104857599, default 50001920):
Using default value 50001920
Last sector, +sectors or +size{K,M,G} (50001920-104857599, default 104857599):
Using default value 104857599
Partition 2 of type Linux and of size 26.2 GiB is set
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d64b4

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857599 52427776 83 Linux

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd99cb4bf

Device Boot Start End Blocks Id System
/dev/vdb1 2048 50000000 24998976+ 83 Linux
/dev/vdb2 50001920 104857599 27427840 83 Linux
mkfs.ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1564672 inodes, 6249744 blocks
312487 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
191 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

mkfs.ext4 /dev/vdb2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1716960 inodes, 6856960 blocks
342848 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
210 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
mkdir /mnt/vdb1
mkdir /mnt/vdb2
mount /dev/vdb1 /data
mount /dev/vdb2 /home
vi /etc/fstab
#add
/dev/vdb1 /data ext4 noatime,nodiratime 0 2
/dev/vdb2 /home ext4 noatime,nodiratime 0 2

5.Create general user account

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#add general user
adduser user
#passwd
passwd user
#check permission
ls -l /etc/sudoers
#if read-only
chmod -v u+w /etc/sudoers
#edit
vim /etc/sudoers
### Allow root to run any commands anywhere
#root ALL=(ALL) ALL
### ADDED
#user ALL=(ALL) NOPASSWD: ALL
#change back to read-only
chmod -v u-w /etc/sudoers
#log as user
su user