Record ssh server configure, like PublicKey or something.
Allow public key authentication for the user
1. Create an SSH key pair
just generate key pair is fine. no matter on server side or client.
ssh-keygen -t rsa
Follow the prompts to save your private key and public key files. By default, they will be saved to ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key). Note that public key will used on server, remote login user use private key.
2. Copy the public key to the server side
upload the public key to server that you want login Type the following command to copy the public key to the Ubuntu server:
ssh-copy-id -i ~/.ssh/id_rsa.pub finuks@81.68.141.136
If this is the first time you’ve connected to the server, you’ll be prompted to accept the server’s fingerprint. Type yes. You’ll then be prompted for the password for the finuks user on the Ubuntu server. Enter it and press Enter. The ssh-copy-id command will copy your public key to the ~/.ssh
3. Configure SSH on the Ubuntu server
open the SSH configuration file with a text editor:
sudo vim /etc/ssh/sshd_config
Find the line that says “#PubkeyAuthentication yes” and uncomment it by removing the # at the beginning of the line. Find the line that says “PasswordAuthentication yes” and change it to “PasswordAuthentication no”. Save the file and exit the text editor.
4. Restart SSH on the Ubuntu server
Type the following command to restart the SSH service:
sudo systemctl restart sshd
5. Test the configuration
From your local machine, type the following command to SSH into the Ubuntu server:
ssh -i ~/.ssh/id_rsa finuks@<ubuntu-server-ip-address>
You should be logged in without being prompted for a password. Type the following command to test sudo:
sudo whoami
You should see the output root without being prompted for a password.
Allow the user to use sudo without a password prompt
Open the sudoers file with a text editor:
sudo vim /etc/sudoers
Find the line that says %sudo ALL=(ALL:ALL) ALL and add the following line below it:
finuks ALL=(ALL:ALL) NOPASSWD: ALL
Save the file and exit the text editor.