How to upload ssh Public Key to windows 2019 server
- User
How to upload ssh Public Key to windows 2019 server
- Assistant
To upload your SSH public key to a Windows 2019 server, you can follow these steps:
- Open the command prompt on your local machine.
- Generate an SSH key pair (public and private key) by running the following command:
cssssh-keygen -t rsa -b 2048This will generate the public and private key files in the default location
~/.ssh/id_rsa.puband~/.ssh/id_rsa, respectively. 3. Copy the contents of the public key file (id_rsa.pub) to your clipboard. You can do this by running the following command:javascriptcat ~/.ssh/id_rsa.pub | clipThis command will copy the contents of the id_rsa.pub file to your clipboard. 4. Log in to your Windows 2019 server using an account that has administrative privileges. 5. Open the Windows PowerShell as Administrator. 6. Create a new directory for your SSH keys by running the following command:
phpNew-Item -ItemType Directory -Path C:\Users\<username>\.sshReplace
<username>with your actual username on the server. 7. Create a new file named authorized_keys by running the following command:phpNew-Item -ItemType File -Path C:\Users\<username>\.ssh\authorized_keys- Open the authorized_keys file by running the following command:
phpnotepad C:\Users\<username>\.ssh\authorized_keys- Paste the contents of your public key that you copied earlier into the authorized_keys file.
- Save and close the authorized_keys file.
- Change the permissions of the .ssh directory and the authorized_keys file by running the following commands:
pythonSet-ItemProperty -Path C:\Users\<username>\.ssh -Name "Attributes" -Value "Directory,Hidden,ReadOnly" Set-ItemProperty -Path C:\Users\<username>\.ssh\authorized_keys -Name "Attributes" -Value "Hidden,ReadOnly"That's it! You should now be able to connect to your Windows 2019 server using SSH with your private key.
- User
請將上述回應內容翻譯成臺灣常用的繁體中文
- Assistant
將您的 SSH 公鑰上傳到 Windows 2019 伺服器的步驟如下:
- 在本機電腦上開啟命令提示字元。
- 執行以下命令產生 SSH 金鑰對(公鑰和私鑰):
cssssh-keygen -t rsa -b 2048這將在預設位置
~/.ssh/id_rsa.pub和~/.ssh/id_rsa產生公鑰和私鑰檔案。 3. 將公鑰檔案(id_rsa.pub)的內容複製到剪貼簿中。您可以執行以下命令完成:javascriptcat ~/.ssh/id_rsa.pub | clip這個命令將會將 id_rsa.pub 檔案的內容複製到剪貼簿中。 4. 使用具有管理權限的帳戶登入 Windows 2019 伺服器。 5. 以系統管理員身份開啟 Windows PowerShell。 6. 執行以下命令建立您的 SSH 金鑰目錄:
phpNew-Item -ItemType Directory -Path C:\Users\<使用者名稱>\.ssh請將
<使用者名稱>替換為您在伺服器上的實際使用者名稱。 7. 執行以下命令建立名為 authorized_keys 的新檔案:phpNew-Item -ItemType File -Path C:\Users\<使用者名稱>\.ssh\authorized_keys- 執行以下命令開啟 authorized_keys 檔案:
phpnotepad C:\Users\<使用者名稱>\.ssh\authorized_keys- 將您先前複製到剪貼簿中的公鑰內容貼上到 authorized_keys 檔案中。