How to use a private key for remote login

This article introduces how to use a private key for remote login with different systems and remote tools

 

Configure the SSH service to allow key-based login

On the remote server, ensure that the configuration of SSH allows key authentication:

  1. Edit the file /etc/ssh/sshd_config :

#sudo vi /etc/ssh/sshd_config

    2. 确保以下行存在,并且没有被注释(没有 #):Make sure the following lines exist and uncommented(no #):

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

PasswordAuthentication no # when you wish to disable password authentication

 

I. Login Method via Mac Terminal

 

1. Download the private key from the remote server

1.1 Use the SCP command to download the private key

Assuming the remote server's IP address is 192.168.1.100, the username is root, and the private key file is located at /root/.ssh/id_ed25519 on the remote server, you can use the SCP (Secure Copy Protocol) to download the private key to your Mac.

Execute the following command on the Mac terminal:

#scp [email protected]:/root/.ssh/id_ed25519 ~/.ssh/id_ed25519

  • [email protected]:The remote server's username and IP address.

  • /root/.ssh/id_ed25519:The path to the private key on the remote server.

  • ~/.ssh/id_ed25519:The path where the private key is stored on the local Mac computer.

If you want to specify the remote server's port, use -P (uppercase P) followed by the port number.

#scp -P 56251 [email protected]:/root/.ssh/id_ed25519 ~/.ssh/id_ed25519

 

1.2 Enter the password.

When executing the above command, the system will prompt you to enter the remote server's password. After entering the password, the private key will be securely copied to the local ~/.ssh/ directory.

For example:

 

2.Ensure the correct permissions for the private key.

2.1 SSH requires the private key file to have specific permissions. Ensure the private key's permissions are set to 600, meaning only the file's owner can read and write it.

Execute the following command on the Mac terminal:

#chmod 600 ~/.ssh/id_ed25519

 

3. Use the private key to log in to the remote server

3.1 Use the ssh command to connect it

Now that you have downloaded the private key to your Mac and set the correct permissions, you can use SSH to connect to the remote server.

Run the following command:

#ssh -i ~/.ssh/id_ed25519 [email protected]

  • -i ~/.ssh/id_ed25519: Specify the private key file.

  • [email protected]: The remote server's username and IP address.

  • If you need to specify the SSH port of the remote server, add -p 56251 at the end.

For example:

If the private key does not have a passphrase, SSH will log in directly. If a passphrase is set, the system will prompt you to enter it.

 

II. windows system

 

1. Download the private key to a Windows system.

Download private key using SCP or FileZilla.

  • If you have SSH access, you can use SCP or FileZilla to download the private key from the remote server to Windows.

  • For example, to download the key to your local machine using FileZilla:

 

III. Putty connection method.

 

1.Download and install PuTTY and PuTTYgen:

1.1 Open PuTTYgen, load the downloaded id_rsa private key file, and save it.

1.2 Finally, click Save private key to generate the private key file.

 

2.Configure the session:

Open PuTTY

2.1 Enter the server's IP address in the Host Name (or IP address) field.

2.2 Enter the SSH port (e.g., 56251) in the Port field.

2.3 Select SSH in the Connection type.

 

3. Load the private key:

3.1 在左侧菜单中,依次展开 Connection > SSH > Auth

3.2 在 Private key file for authentication 中,点击 Browse,选择你保存的 .ppk 文件(如 id_ed25519.ppk)。

 

4. 连接服务器:

4.1 点击 Open,启动连接。

4.2 输入用户名(如 root),然后按回车。

4.3 如果一切正常,你应该会成功登录到服务器。

 

四、xshell连接方式

 

打开 Xshell:

  1. 创建新会话

点击菜单栏的 文件 > 新建,打开新建会话窗口。

  1. 配置连接信息

连接 选项卡中:

  • 名称:输入会话名称。

  • 协议:选择 SSH

  • 主机:输入服务器的 IP 地址(如 107.149.212.85)。

  • 端口号:输入 SSH 端口(如 56251)。

 

  1. 配置身份验证

  • 用户密钥:点击 浏览,选择你下载到本地的私钥文件(如 id_ed25519)。

  • 如果私钥有密码,在 密码 中输入私钥的密码。

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Manual installation of the operating system on the public cloud

1.Log in to the raksmart backend and click on "Products & Services."   2.Enter the cloud...

To enable Google two-factor authentication in the public cloud

To ensure the security of user Rak Cloud management panel, Rak Cloud service panel supports...

How to build an internal network in the public cloud

To create an internal network for cloud virtual machines, ensure that the machines are on the...

How to enter rescue mode in public cloud

1. If the server's operating system cannot boot normally but you need to back up data, you can...

Operating the Public Cloud Snapshot/Backup Function

1.In the backend, go to "Product Services" and click on "Public Cloud." Find the desired product...