Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Created May 16, 2023 11:14
Show Gist options
  • Save Hansimov/bae4df07f1abcb7e8086c43eec83e085 to your computer and use it in GitHub Desktop.
Save Hansimov/bae4df07f1abcb7e8086c43eec83e085 to your computer and use it in GitHub Desktop.
Remote-SSH server issues

If cannot ssh to remote server with password, it is possibly because that the remote server does not enable PasswordAuthentication.

So we need to use the method of public keys to login.

Run in Local Machine:

ssh-keygen

This will generate a key pair for ssh.

Then copy the public to remote server.

Run in Local Machine:

  • Normally, ssh-copy-id is available in Git console.
ssh-copy-id <username>@<remote_server>

After steps above, we could login remote server with the following command:

  • Do not forget to specify <username>@
ssh <username>@<remote_server>

Or if use a config file (C:\Users\xxx\.ssh\config) for ssh, you need to add the User <username> entry:

Host <server>
    HostName <server_name>
    User <username>
@Hansimov
Copy link
Author

Bing Chat History

How to solve this error when using ssh to login to remote server: "Permission denied (publickey,gssapi-with-mic,keyboard-interactive)"

The “Permission denied (publickey,gssapi-with-mic,keyboard-interactive)” error appears after permission-related settings are modified on the SSH server. One reason for the error may be sshd_config, the file that contains SSH server configuration. The other possibility is that the authorized_keys file has insufficient permissions1.

You can try to fix this issue by enabling password login in the sshd_config file. To do this, open the file in a text editor and find the PasswordAuthentication line and make sure it ends with yes. Find the ChallengeResponseAuthentication option and disable it by adding no. If lines are commented out, remove the hash sign # to uncomment them. Save the file and exit. Restart the SSH service by typing the following command: sudo systemctl restart sshd1.

Would you like more information on this topic?

  1. How to Fix SSH Failed Permission Denied (publickey,gssapi-keyex,gssapi ...
  2. ssh : Permission denied (publickey,gssapi-with-mic)

how could I find the path of sshd_config and ChallengeResponseAuthentication

The sshd_config file is usually located at /etc/ssh/sshd_config1. The ChallengeResponseAuthentication option is located within this file. You can open the file in a text editor and find the ChallengeResponseAuthentication line to make changes1.

Is there anything else you would like to know?

  1. The default value for the "ChallengeResponseAuthentication" in "/etc ...
  2. "ChallengeResponseAuthentication" is missing in Debian sshd_config

How to use linux command to find file sshd_config

You can use the find command to search for the sshd_config file in your Linux system. Here’s an example command that searches for the file in the /etc directory:

sudo find /etc -name sshd_config

Copy

This command will return the path of the sshd_config file if it is located within the /etc directory. You can also search in other directories by replacing /etc with the path of the directory you want to search in.

Is there anything else you would like to know?

What if I am not the admin, how could I set PasswordAuthentication to yes in my user account in Linux?

If you are not an administrator on the Linux system, you will not have permission to modify the sshd_config file. This file is usually owned by the root user and only users with sudo or root privileges can modify it.

In this case, you will need to contact the system administrator and request that they make the change for you. They will be able to modify the PasswordAuthentication option in the sshd_config file to enable password authentication for SSH.

Is there anything else you would like to know?

Then how could I login my user account in remote server via ssh with username and password?

If the PasswordAuthentication option is set to yes in the sshd_config file on the remote server, you can log in to your user account via SSH using your username and password. Here’s an example command that you can use to log in:

ssh username@remote_server_ip

Copy

Replace username with your username on the remote server and remote_server_ip with the IP address of the remote server. After running this command, you will be prompted to enter your password. Once you enter your password, you will be logged in to your user account on the remote server.

Is there anything else you would like to know?

If PasswordAuthentication is no, and I am not a root user, how could I login

If PasswordAuthentication is set to no on the remote server, you will not be able to log in via SSH using a password. Instead, you will need to use public key authentication.

To use public key authentication, you will need to generate a key pair on your local machine and add the public key to the authorized_keys file on the remote server. Here’s an example of how you can generate a key pair on your local machine:

ssh-keygen

Copy

This command will generate a new key pair and save it in the ~/.ssh directory. You can then copy the public key to the remote server using the ssh-copy-id command:

ssh-copy-id username@remote_server_ip

Copy

Replace username with your username on the remote server and remote_server_ip with the IP address of the remote server. This command will add your public key to the authorized_keys file on the remote server.

Once your public key has been added to the authorized_keys file on the remote server, you can log in via SSH without entering a password. The ssh command will use your private key to authenticate you automatically.

Is there anything else you would like to know?

'ssh-copy-id' is not recognized as an internal or external command

It seems that the ssh-copy-id command is not available on your system. This command is usually included with the OpenSSH package, but it may not be installed on all systems.

If ssh-copy-id is not available on your system, you can manually copy your public key to the remote server. Here’s an example of how you can do this:

  1. On your local machine, display the contents of your public key file using the cat command:

    cat ~/.ssh/id_rsa.pub

Copy

This command will display the contents of your public key file. Select and copy the entire key to your clipboard.

  1. Log in to the remote server via SSH using your username and password:

    ssh username@remote_server_ip

Copy

Replace username with your username on the remote server and remote_server_ip with the IP address of the remote server. After running this command, you will be prompted to enter your password.

  1. Once you are logged in to the remote server, open the authorized_keys file in a text editor:

    nano ~/.ssh/authorized_keys

Copy

This command will open the authorized_keys file in the nano text editor. You can use a different text editor if you prefer.

  1. Paste your public key into the authorized_keys file and save the changes.

After adding your public key to the authorized_keys file on the remote server, you should be able to log in via SSH without entering a password.

Is there anything else you would like to know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment