Get the App
SLTechnology News&Howtos  ›  Servers  › 

Set key to log in on linux and add sudo permissions to ordinary users

Shulou Source: shulou.com Published: 2022-06-02 23:40:56 09月22日 Update

Take the xshell connection tool as an example

Generate secret key

Select RSA as the key type. Next step

Name customization. Next step

You can save a copy of the key to the computer and finish it.

The picture below is the private key, or you can save a copy to the computer.

The private key is reserved for connecting to the server, and the public key is transferred to the server configuration file (how to pass it later)

Operations on the server

1. Transfer the public key to the server under the root directory

two。 Execute the command to write to the key profile

Ssh-keygen-X-f xjw.pub > > / root/.ssh/authorized_keys2

The error is reported because there are no .ssh directories and files. The solution is to link to the server.

Command line input: ssh localhost

Execute it again and you will have: ssh-keygen-X-f xjw.pub > > / root/.ssh/authorized_keys2

1. Modify the configuration file: vim / etc/ssh/sshd_config

Modify ssh connection port (default 22, modify if necessary): search for Port

two。 Modify access key file path

Search for AuthorizedKeysFile, which is commented out by default, and accesses the .ssh / authorized_keys file. If you want to change it or not, I have created a new authorized_keys2 here.

3. Modify and cancel password login

Search PasswordAuthentication and change yes to no

Note: if you find a machine that can neither log in with a password nor log in with a key, you need to check these two lines of configuration files to see whether they have been uncommented and changed to no. Both are allowed by default.

# RSAAuthentication yes

# PubkeyAuthentication yes

Restart the sshd service: service sshe restart

Add sudo permissions to ordinary users

Create a normal user

[root@localhost ~] # useradd test1

Add permission

Modify the configuration file:

[root@localhost ~] # vim / etc/sudoers

Find the configuration of the root user and add it below him.

Note: user's method of changing password

Local user changes password: passwd

Change other user passwords: passwd username

Tags: File user service configuration key password server comment search normal permission login public key command computer directory following figure again method name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info OPPO Reno Apple Shulou Information