RHEL/CENTOS 7/8 crack root password
Implementation steps
When the system starts, press any key to pause the startup
Press e to enter edit mode
Move the cursor to the line starting with linux and add the kernel parameter rd.break
Press ctrl-x to start into rescue mode
Press e to enter edit mode
Move the cursor to the line starting with linux, add the kernel parameter rd.break, press ctrl-x to start and enter the rescue mode
Reset root password
mount –o remount,rw /sysroot
chroot /sysroot
passwd root
# If SELinux is enabled,Only need to perform the following operations,If it does not start,No need to execute
touch /.autorelabel
exit
reboot
After the system restarts, enter the modified password
CentOS 8 ssh password-free login
Implementation steps
Local end: 192.168.99.222
Server side: 192.168.99.233
Generate secret key locally
ssh-keygen -t rsa
View the secret key file locally
[ root@zabbix-centos8 ~]# cd .ssh/[root@zabbix-centos8 .ssh]# ls -al
total 8
drwx------2 root root 38 Jun 103:26.
dr-xr-x---.3 root root 185 Jun 103:26..-rw-------1 root root 2602 Jun 103:26 id_rsa
- rw-r--r--1 root root 573 Jun 103:26 id_rsa.pub
Server-side directory permissions
The .ssh/ folder in the user root directory, modify the folder permissions to 700 (if there is no .ssh directory, you need to create it manually)
mkdir .ssh
chmod 700.ssh
Local synchronization public key
method one
The ssh-copy-id command can copy the public key of the local host to the authorized_keys file of the remote host, and the ssh-copy-id command will also give the user home directory (home) and ~/.ssh, and ~/ of the remote host. ssh/authorized_keys set appropriate permissions.
grammar
ssh-copy-id [-i [identity_file]][user@]machine
Options
[ root@zabbix-centos8 ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
** Method Two**
Add the data in the local id_rsa.pub to the server side.ssh/authorized_keys
[ root@zabbix-centos8 ~]#cat ~/.ssh/id_rsa.pub | ssh [email protected] 22'cat >> .ssh/authorized_keys'
View authorized_keys file
[ root@kafka-node2 .ssh]# ls -altotal 8drwx------.2 root root 48 May 3119:35.dr-xr-x---.3 root root 163 May 3119:39..-rw-r--r--1 root root 573 May 3119:35 authorized_keys-rw-r--r--.1 root root 188 Apr 1910:52 known_hosts
ssh allows login with key by default
Edit ssh configuration file
vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
Restart service
systemctl restart sshd
Local login test
Mount the local iso image
Mount the image to the file directory
mkdir /mnt/cdrom
mount -o loop /dev/sr0 /mnt/cdrom/
Edit repo file
vi /etc/yum.repos.d/CentOS-Media.repo
[ InstallMedia]
name=CentOS Linux 8
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0
enabled=1[AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0
List RPM packages
dnf list
dnf list |grep nginx
Recommended Posts