Linux server configuration using key login

Step 1: Log in to the server: and execute the following commands to generate the key and public key


[root@ecs-004 ~]ssh-keygen -t rsa

 Step 2: Configure ssh to use a key

#进入 ssh 目录
cd ~/.ssh 或者 cd /root/.ssh/
 
#然后安装公钥 authorized_keys 
cp id_rsa.pub authorized_keys
 
#注意,如果存在 authorized_keys 则采用写入方式
cat id_rsa.pub >> authorized_keys

#设置公钥权限
chmod 600 authorized_keys
chmod 700 ~/.ssh

Step 3: Modify the ssh configuration file

vim  /etc/ssh/sshd_config
 
然后对应如下修改:
 
StrictModes no  #此项默认为注释关闭
 
PubkeyAuthentication yes
RSAAuthentication yes    #默认不存在,可放到上面一行的下边
AuthorizedKeysFile      .ssh/authorized_keys      #ssh文件位置,此项默认设置相同
PasswordAuthentication yes                        #使用密码  no为不使用密码

Step 4: Restart the sshd service and export the private key

#  重启sshd服务
systemctl restart sshd.service

#  下载lrzsz服务
yum install -y lrzsz

#  导出私钥
sz id_rsa

Step 5: Verify whether xshell is available

1. Enter the target server IP

2. Import the key

3. Identity verification

4. Click to connect

Guess you like

Origin blog.csdn.net/ArrogantB/article/details/127048490