1. Configure the network environment
Centos7 download:
http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
1.1. Configure ip address:
[root@localhost85~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=c1fa9edb-773e-48d2-83cf-82e8b01ffbb0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR = 00: 0C: 29: 4E: A6: 48
IPADDR=192.168.1.85
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DEFROUTE = yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=eth0
[root@localhost85~]#
1.2. Set ip address mapping:
[root@localhost85~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4
::1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.1.85localhost85
~
[root@localhost85~]#
1.3. Setting the hostname
[root@localhost85~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost85
GATEWAY=192.168.1.1
~
[root@localhost85~]#
1.4. Turn off selinux
[root@localhost85~]# vim /etc/selinux/config
# This file controlsthe state of SELinux on the system.
# SELINUX= can takeone of these three values:
# enforcing - SELinux security policy isenforced.
# permissive - SELinux prints warningsinstead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= cantake one of these two values:
# targeted - Targeted processes areprotected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost85~]#
1.5. Turn off the firewall
[root@localhost85~]#
[root@localhost85~]# iptables -F
[root@localhost85~]# /etc/init.d/iptables save #Save rules
iptables: save firewall rules to /etc/sysconfig/iptables: [OK]
[root@localhost85~]#
[root@localhost85~]# chkconfig iptables off #Turn on and off
[root@localhost85~]# chkconfig --list
[root@localhost85~]#reboot #Restart
1.6. Generate ssh keyless login
[root@localhost85~]#
[root@localhost85~]# ssh-keygen
Generatingpublic/private rsa key pair.
Enter file in whichto save the key (/root/.ssh/id_rsa):
Enter passphrase(empty for no passphrase):
Enter samepassphrase again:
Your identificationhas been saved in /root/.ssh/id_rsa.
Your public key hasbeen saved in /root/.ssh/id_rsa.pub.
The key fingerprintis:
13:f1:e5:a3:62:ac:ce:ad:63:72:d1:6f:4a:89:de:5broot@localhost85
The key's randomart imageis:
+---[ RSA 2048]----+
| . . |
| oo |
| . . the |
| . . . . |
| .S . |
| .+.+ |
| ooE |
| .+++ .o |
| +=o=+ |
+-----------------+
[root@localhost85~]#
[root@localhost85~]# ls /root/.ssh/
id_rsa id_rsa.pub known_hosts
[root@localhost85~]#
[root@localhost85~]#
[root@localhost85~]# ssh-copy-id -i /root/.ssh/id_rsa [email protected]
[email protected]'spassword:
Now try logging intothe machine, with "ssh '[email protected]'", and check in:
.ssh/authorized_keys
to make sure wehaven't added extra keys that you weren't expecting.
[root@localhost85~]#
[root@localhost85~]# ls /root/.ssh/
authorized_keys id_rsa id_rsa.pub known_hosts
[root@localhost85~]#
With the above configuration, you can log in directly through ssh without password authentication