MAC password-free login server

1. Open the terminal on the Mac to generate public and private keys

Enter ssh-keygen, just enter all the way, and you can also enter the password at the arrow
insert image description here

2. Find the public key just generated

Enter the folder where id_rsa and id_rsa.pub are located in the above picture, it is possible to enter the hidden folder .ssh, you can use Command + Shift + . This shortcut key to view hidden folders. The first is the private key, and the one ending in .pub is the public key.
insert image description here

3. Upload the public key to the remote Linux server

scp ~/.ssh/id_rsa.pub root@ip:~/.ssh

4. Remotely log in to the Linux system server to perform the following operations

cd ~
cd .ssh
chmod 700 .ssh
#将公钥内容写入
cat id_rsa.pub >> authorized_keys
#给权限
chmod 600 authorized_keys

5. After setting, exit the terminal and enter the following command to log in without password

ssh root@ip

6. Forbid Linux to log in with account and password

#进入ssh配置目录
cd /etc/ssh/

#修改 SSH 的配置文件 
vi sshd_config

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

#默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录 只改这个就行
PasswordAuthentication no

3. Restart the ssh service

systemctl restart sshd.service

Guess you like

Origin blog.csdn.net/qq_37924396/article/details/130781378