Chenghsien Lin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Git - SSH Key ###### tags: `Git` `SSH Key` MAC/ Windows Git via SSH # ppk file to pem file in MAC: ``` puttygen <your-putty-key.ppk> -O private-openssh -o <your-ssh-key.pem> puttygen 2020_04_05.ppk -O private-openssh -o 2020_04_05.pem ``` # add existing ssh key in MAC: ``` ssh-add -k ~/.ssh/[your-private-key] ssh-add -k 2020_04_05.pem ``` ## Error when ``ssh-add`` ### [Could not open a connection to your authentication agent](https://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent) #### Question: ![](https://i.imgur.com/DCt7F0o.png) I am running into this error of: ``` $ git push heroku master Warning: Permanently added the RSA host key for IP address '50.19.85.132' to the list of known hosts. ! Your key with fingerprint b7:fd:15:25:02:8e:5f:06:4f:1c:af:f3:f0:c3:c2:65 is not authorized to access bitstarter. ``` I tried to add the keys and I get this error below: ``` $ ssh-add ~/.ssh/id_rsa.pub Could not open a connection to your authentication agent. ``` #### Answer: ### Did You Start ssh-agent? You might need to start ssh-agent before you run the ssh-add command: ``` eval `ssh-agent -s` ssh-add ``` ![](https://i.imgur.com/sY6IxzR.png) # file too open access: ``` chmod 600 config chmod 600 2020_04_05.pem ``` # Test connect to Github/ BitBucket: ``` ssh -T git@github.com ssh -T git@bitbucket.org ``` --- # ssh config: ``ssh-keygen`` 會建立 ``~/.ssh`` 目錄和預設的 public / private keys ## /.ssh/config: ``` Host * UseKeychain yes <-- Mac os only AddKeysToAgent yes IdentityFile /Users/xxxx/folder/yyyy.pem ``` Windows 在 ``C:\Users\<User_Name>\.ssh\`` 目錄下 全部使用相同 ``` Host * AddKeysToAgent yes IdentityFile D:\kye_hss\2020_04_05\2020_04_05.pem ``` 各別設定 ``` Host git.tw-futaba.com.tw AddKeysToAgent yes IdentityFile C:\Users\elite\.ssh\futaba_gitlab.pem Host github.com AddKeysToAgent yes IdentityFile C:\Users\elite\.ssh\2023_05_16.pem Host bitbucket.org AddKeysToAgent yes IdentityFile C:\Users\elite\.ssh\2023_05_16.pem ``` --- # ppk file to pem file in windows: ![](https://i.imgur.com/oG2Mcw4.png) ![](https://i.imgur.com/NcudVeH.png) --- ## chmod 600 in windows: [Windows CHMOD 600](https://stackoverflow.com/questions/5264595/windows-chmod-600) [Windows SSH: Permissions for 'private-key' are too open](https://superuser.com/questions/1296024/windows-ssh-permissions-for-private-key-are-too-open) ![](https://i.imgur.com/zchq9kI.png) ![](https://i.imgur.com/N4Sj05H.png) ![](https://i.imgur.com/TShdItv.png) [如何用config管理多個網站的ssh key和如何不用每一組輸入ssh的Pass Phrase](https://blog.alantsai.net/posts/2016/03/ssh-config-ssh-agent-passphrase-management) --- http://git-server.goglobal.com.tw/help/ssh/README#generating-a-new-ssh-key-pair Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com" Or, if you want to use RSA: ``` ssh-keygen -t rsa -b 4096 -C "email@example.com" ssh-keygen -t rsa -b 4096 -C "elite_lin@goglobal.com.tw" ``` ``` C:\Users\Elite_lin>ssh-keygen -t rsa -b 4096 -C "elite_lin@goglobal.com.tw" Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\Elite_lin/.ssh/id_rsa): gitlab_ssh_key Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in gitlab_ssh_key. Your public key has been saved in gitlab_ssh_key.pub. The key fingerprint is: SHA256:7WhtXVbxp2IPJlR6EAAIDgeKDYvpZ/6640Wv7umKrxI elite_lin@goglobal.com.tw The key's randomart image is: +---[RSA 4096]----+ |+.o. .....o.. . | |+O . + o| |* o o . +| |. o . o.| | . o . S o = + | |E + . . + = * | | . . . .o + . . | |. ..o o. . | |.o+*OB | +----[SHA256]-----+ ``` similar to ``cat`` ``` C:\Users\Elite_lin>type * ``` --- by eaddy - 2022/08/26 ``` elite@fwteam-BM1AF-BP1AF-BM6AF:~$ ssh-keygen -t rsa -b 2048 -C "elite_lin" Generating public/private rsa key pair. Enter file in which to save the key (/home/elite/.ssh/id_rsa): Created directory '/home/elite/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/elite/.ssh/id_rsa Your public key has been saved in /home/elite/.ssh/id_rsa.pub The key fingerprint is: SHA256:CfsB05oV7EPrrGAXOS44mOelaa3EEP2NiDtoUP3Ncf8 elite_lin The key's randomart image is: +---[RSA 2048]----+ |       ..        | | . .   .o.       | |. o . +++..      | | + o ++@++ .     | |+o..o.*=S.  .    | |=++ = o.o.   .   | |++oB + ..     E  | |.o= . .          | | ...             | +----[SHA256]-----+ elite@fwteam-BM1AF-BP1AF-BM6AF:~$ ls .ssh/id_rsa id_rsa      id_rsa.pub ``` ---- Git 出錯 error message 類似 >HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab.com/my_username/my-repo.git/' `` solution: [How to view, add, remove or edit the saved Users names and passwords on a given system](https://support.microsoft.com/en-ca/help/555631) type in: ``` rundll32.exe keymgr.dll,KRShowKeyMgr ``` --- # ssh-agent ## [[faq]Windows 1803之後git for windows無法透過Start-SshAgent啓用ssh agent - 需要一直輸入passphrase的問題](https://blog.alantsai.net/posts/2018/11/faq-start-sshagent-error-1058-on-windows-1803-cannot-use-ssh-agent) 不過用ssh又遇到另外一個問題,每一次和遠端溝通都要輸入passphrase超級麻煩, 這個時候突然想起以前寫過(何謂ssh,在Windows下如何使用ssh, 如何在Windows透過ssh下載和上傳程式到github)透過ssh agent不用一直輸入密碼。 興奮的打開那一篇,學著裡面輸入Start-SshAgent,結果出現了error:1058。 ### 解決方式 - TL;DR 以下解法適合 Windows 10 1803的作業系統 - 不知道未來微軟是否會調整,但是至少在1803會有這個問題。 需要執行以下幾個動作即可解決: 1. 把 ``ssh-agent`` 這個service 從 ``disabled`` 狀態改成 ``manual`` 可以透過gui的方式去設定(顯示名稱是:OpenSSH Authentication Agent) 如果透過powershell則是: ``` Set-Service ssh-agent -StartupType Manual ``` 2. 調整git使用内建帶的ssh agent 透過指令執行: ``` git config --global core.sshCommand "'C:/Windows/System32/OpenSSH/ssh.exe'" ``` 做完了以上兩個動作之後,未來需要啓動ssh agent的時候 只需要輸入Start-SshAgent。接下來和遠端溝通都不需要一直輸入passphrase - 太棒了。 如果對於爲什麽要做上面兩個事情有興趣的話請繼續往下看。 --- ## https://stackoverflow.com/questions/52113738/starting-ssh-agent-on-windows-10-fails-unable-to-start-ssh-agent-service-erro I solved the problem by changing the ``StartupType`` of the ``ssh-agent`` to ``Manual`` via ``Set-Service ssh-agent -StartupType Manual``. Then I was able to start the service via ``Start-Service ssh-agent`` or just ``ssh-agent``. --- ## My exercise ``` unable to start ssh-agent service, error :1058 PS D:\GitLab_Runner> et-Service ssh-agent et-Service: The term 'et-Service' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS D:\GitLab_Runner> Get-Service ssh-agent Status Name DisplayName ------ ---- ----------- Stopped ssh-agent OpenSSH Authentication Agent PS D:\GitLab_Runner> Start-Service ssh-agent Start-Service: Service 'OpenSSH Authentication Agent (ssh-agent)' cannot be started due to the following error: Cannot start service 'ssh-agent' on computer '.'. PS D:\GitLab_Runner> Start-Service ssh-agent.exe Start-Service: Cannot find any service with service name 'ssh-agent.exe'. PS D:\GitLab_Runner> Start-SshAgent Start-SshAgent: The term 'Start-SshAgent' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS D:\GitLab_Runner> Set-Service ssh-agent -StartupType Manual PS D:\GitLab_Runner> Start-SshAgent Start-SshAgent: The term 'Start-SshAgent' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS D:\GitLab_Runner> Start-Service ssh-agent PS D:\GitLab_Runner> Get-Service ssh-agent Status Name DisplayName ------ ---- ----------- Running ssh-agent OpenSSH Authentication Agent ``` --- # Windows ssh 錯誤 ### 2023/02/28 ``` Enter passphrase for key 'C:\Users\elite\.ssh\2020_04_05.pem': tfsc\\elite@bitbucket.org: Permission denied (publickey). ``` ![](https://i.imgur.com/nytOIyr.png) 1. 首先, 確定Windows 有安裝 OpenSSH Client ![螢幕擷取畫面 2024-12-03 081552](https://hackmd.io/_uploads/B1XDRaiQyx.png) ![螢幕擷取畫面 2024-12-03 081706](https://hackmd.io/_uploads/HkwvAajXkx.png) ![螢幕擷取畫面 2024-12-03 081737](https://hackmd.io/_uploads/HyqwA6oXkx.png) 2. 目前使用者的目錄下, 沒有 ``.ssh`` 這個資料夾, 其內也沒有 ``id_rsa`` 與 ``id_rsa.pub`` 這兩個檔案 3. 以系統管理員身份來開啟 PowerShell 7 ![](https://i.imgur.com/qm2k9ss.png) 然後輸入 ``ssh-keygen`` 按 Enter 走預設的值 ``` PS C:\Windows\System32> ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\elite/.ssh/id_rsa): Created directory 'C:\\Users\\elite/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in C:\Users\elite/.ssh/id_rsa Your public key has been saved in C:\Users\elite/.ssh/id_rsa.pub The key fingerprint is: SHA256:+qGfUe/tsvogKkRdsC1sQTbeDXf9pKN7HAeGdj9wmy4 tfsc\elite@AS81739B The key's randomart image is: +---[RSA 3072]----+ | .*.. . .. | | + *.+ . . .| | .*.o . . + | | .... o.*..| | . S .. +o+o| | . . . .. .+o| | . . + . .o.o.| | . + = ooEo. | | .o.+ .o+=+ | +----[SHA256]-----+ PS C:\Windows\System32> ``` ![](https://i.imgur.com/g2aQNC0.png) 4. 然後 自己專用的 private key (``*.pem``) 檔案 要確定 __擁有者__ 是__目前的使用者__ 然後把下方的 __繼承__ 停用 然後中間的 __主體__ 只留下 __目前的使用者__, 並確定能 __完全控制__ ![](https://i.imgur.com/o47ybkn.png) ![](https://hackmd.io/_uploads/rJ2Y0bH2n.png) ![](https://hackmd.io/_uploads/Sy750Zrhn.png) ![](https://hackmd.io/_uploads/rkPc0bHh3.png) ![](https://hackmd.io/_uploads/Hy6cCWr23.png) 最後會像這樣 ![](https://hackmd.io/_uploads/SkfjCZB23.png) ![](https://hackmd.io/_uploads/ry3j0-r32.png) ## Ref * https://phoenixnap.com/kb/generate-ssh-key-windows-10 * https://stackoverflow.com/questions/64687271/how-to-avoid-permission-denied-publickey-ssh-key-windows # SourceTree ## Ref * [Trust A Server's Host Key when No Button is Available to Trust It](https://confluence.atlassian.com/sourcetreekb/trust-a-server-s-host-key-when-no-button-is-available-to-trust-it-788731545.html) * [SourceTree error: The server's host key is not cached in the registry.](https://community.atlassian.com/t5/Sourcetree-questions/SourceTree-error-The-server-s-host-key-is-not-cached-in-the/qaq-p/1410001) ![](https://i.imgur.com/85y29Q5.png) ![](https://i.imgur.com/reVtOGY.png) ``` cd C:\Users\elite\AppData\Local\SourceTree\app-3.4.11\tools\putty PS C:\Users\elite\AppData\Local\SourceTree\app-3.4.11\tools\putty> ls Directory: C:\Users\elite\AppData\Local\SourceTree\app-3.4.11\tools\putty Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 2023/3/1 上午 11:36 762648 pageant.exe -a--- 2023/3/1 上午 11:36 858416 plink.exe -a--- 2023/3/1 上午 11:36 855832 puttygen.exe PS C:\Users\elite\AppData\Local\SourceTree\app-3.4.11\tools\putty> .\plink.exe bitbucket.org PS C:\Users\elite\AppData\Local\SourceTree\app-3.4.11\tools\putty> .\plink.exe github.com ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully