Github Action SSH to remote user using private key.

DevOps_Boy

Active member
  • Jul 28, 2023
    238
    120
    43
    මචන්. මම ඩිප්ලෝයිමන්ට් කරනවා github action වලින්. ගොඩක් aws servers. pem file තියන නිසා අවුලක් නෑ. ඒත් මට තව සර්වර් එකක් දුන්නා ඩෙප්ලොයිමන්ට් දාන්න. ඒක AWS නෙමෙයි තියෙන්නේ. dialog IDC එකේ virtual server එකක්. අනිත් aws servers වලට අවුලක් නෑ ගානට වැඩේ වෙනවා. ඒත් මේ සර්වර් එකට දාන්න බෑ Error එකක් එනවා. මම ඒක දන්නම් පහතින්. මම ඩිප්ලෝයි කරන්න යූස් කරන්නෙ github market place eken gaththu rsync module එකක්. මම ඒ සර්වර් එකේ අලුත් යූසර් කෙනෙක් හැදුවා deployer කියල.ඊටපස්සේ ඒ යූසර්ට ssh keys දැම්මා. මොකද මම යූස් කරන මොඩියුල් එකට අනිවා .PEM file එකක් දෙන්න ඔනේ. මට අලුතින් හම්බුන සර්වර් එක Password and username ගහලා ලොග් වෙන්න remote SSH කරන්න පුලුව්න්. ඒත් winscp කරන්න යද්දි server refesed our key කියලා එනවා. මම /etc/ssh/sshd_config file එකේ PubkeyAuthentication yes කරලා SSH restart කලා. හැබැයි අලුත් username and password වලින් ssh කරන්න පුලුවන් අවුලක් නැතුව. winscp එකෙනුයි github action එකෙනුයි තමා බැරි. chatGPT එකේ තිබ්බ ඒවත් try කලාට හරි ගියේ නෑ. මේකට මොකද්ද කරන්න පුලුව්න්?????

    මම remote server එකෙ private key generate කලේ මෙකෙන් - "ssh-keygen -m PEM -t rsa -b 4096"

    script:
    YAML:
    name: Deploy to WAR files to github AWS LightSail
    on:
      push:
        branches: main
    
    jobs:
        Get_code:
            runs-on: ubuntu-20.04
            steps:
                - name: Get code
                  uses: actions/checkout@v4
                - name: Getting deatails of the server
                  run: |
                    lscpu
                    free -h
                - name: Go to folder
                  run: |
                    cd /home/runner/work/API-Service/API-Service
                    ls -l
                - name: Deploy to the Dialer server.
                  uses: easingthemes/ssh-deploy@main
                  with:
                    SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_TEST }}
                    SOURCE: "*"
                    REMOTE_HOST: "202.129.81.20"
                    REMOTE_PORT: "22"
                    REMOTE_USER: "deployer"
                    TARGET: "/opt/cicd_testing/api"
    Code:


    error:
    Code:
    Run easingthemes/ssh-deploy@main
      with:
        SSH_PRIVATE_KEY: ***
        SOURCE: *
        REMOTE_HOST: 202.129.81.20
        REMOTE_PORT: 22
        REMOTE_USER: deployer
        TARGET: /opt/cicd_testing/api
        ARGS: -rlgoDzvc -i
        SSH_CMD_ARGS: -o StrictHostKeyChecking=no
    [DIR] Creating /home/runner/.ssh dir in workspace root
    ✅ [DIR] dir created.
    [FILE] writing /home/runner/.ssh/known_hosts file ... 0
    ✅ [SSH] known_hosts file ensured /home/runner/.ssh
    ✅ [DIR] /home/runner/.ssh dir exist
    [FILE] writing /home/runner/.ssh/deploy_key_root_1696537420158 file ... 3243
    ✅ [SSH] key added to `.ssh` dir  /home/runner/.ssh deploy_key_root_1696537420158
    rsync  version 3.1.3  protocol version 31
    Copyright (C) 1996-2018 by Andrew Tridgell, Wayne Davison, and others.
    Web site: http://rsync.samba.org/
    Capabilities:
        64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
        socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
        append, ACLs, xattrs, iconv, symtimes, prealloc
    
    rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
    are welcome to redistribute it under certain conditions.  See the GNU
    General Public Licence for details.
    ✅️ [CLI] Rsync exists
    [Rsync] Starting Rsync Action: /home/runner/work/API-Service/API-Service/* to [email protected]:/opt/cicd_testing/api
    [Rsync] excluding folders
    Warning: Permanently added '[202.129.81.20]:22' (ECDSA) to the list of known hosts.
    
    Permission denied, please try again.
    
    Permission denied, please try again.
    
    [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
    
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]
    
    ❌ [Rsync] error:
    Error: rsync exited with code 255
    rsync /home/runner/work/API-Service/API-Service/* [email protected]:/opt/cicd_testing/api --rsh "ssh -p 22 -i /home/runner/.ssh/deploy_key_root_1696537420158 -o StrictHostKeyChecking=no" --recursive --exclude= -rlgoDzvc -i
        at ChildProcess.<anonymous> (/home/runner/work/_actions/easingthemes/ssh-deploy/main/dist/index.js:2:2603)
        at ChildProcess.emit (node:events:513:28)
        at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12) {
      code: 255
    }
    ❌ [Rsync] stderr:
    Warning: Permanently added '[202.129.81.20]:22' (ECDSA) to the list of known hosts.
    Permission denied, please try again.
    Permission denied, please try again.
    [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]
    
    ❌️ [Rsync] stdout:
    
    ❌ [Rsync] command:
    ================================================================
    ================================================================
    Error: R] rsync exited with code 255
    
    Warning: Permanently added '[202.129.81.20]:22' (ECDSA) to the list of known hosts.
    Permission denied, please try again.
    Permission denied, please try again.
    [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]


    මම යූස් කරපු SSH module එක
    https://github.com/easingthemes/ssh-deploy
     

    DevOps_Boy

    Active member
  • Jul 28, 2023
    238
    120
    43
    SSH Key type eka mokada?

    OpenSSH version eka mokakda?

    OpenSSH 8.8 wada wadi nam RSA keys wada karanne na.
    SSH key type eka RSA. mama generate kale me command eken "ssh-keygen -m PEM -t rsa -b 4096" . mama github action walata use krnna github shared runners. ethakota github hosted server eketh OpenSSH version balanna weida? mage remote server eke nm thiyenne OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017.
    mama dn github hosted runner eke beluwama thibbe me version eka - OpenSSH_8.2p1 Ubuntu-4ubuntu0.9, OpenSSL 1.1.1f 31 Mar 2020

    mokak wenna puluwnda awla?
     
    Last edited:

    DevOps_Boy

    Active member
  • Jul 28, 2023
    238
    120
    43
    machan selinux disable krala thiyenne already. - SELinux status: disabled
    Easy fix eka.
    Remote server eke selinux disable karala balapan badu wada karai. Hari giyoth kiyanna proper fix ekak dennam
    wena krnna kramyak thiyeda machan?
     

    Honda.putha

    Well-known member
  • Dec 26, 2017
    17,242
    29,818
    113
    SSH key type eka RSA. mama generate kale me command eken "ssh-keygen -m PEM -t rsa -b 4096" . mama github action walata use krnna github shared runners. ethakota github hosted server eketh OpenSSH version balanna weida? mage remote server eke nm thiyenne OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017.
    mama dn github hosted runner eke beluwama thibbe me version eka - OpenSSH_8.2p1 Ubuntu-4ubuntu0.9, OpenSSL 1.1.1f 31 Mar 2020

    mokak wenna puluwnda awla?
    no idea ban. ekko ed25519 hari ECDSA key ekak dala check karala balapan.
     
    • Like
    Reactions: DevOps_Boy

    DevOps_Boy

    Active member
  • Jul 28, 2023
    238
    120
    43
    Thank you Guys - wede hari giya.
    IP Address පබ්ලික් දාන්න එපා යකෝ.
    මෙක ට්‍රයි කරල බැලුවද?
    https://superuser.com/questions/1454387/rsync-permission-denied-publickey-with-ssh
    ne mchn mama IP eka change krla demme. thank you broo

    P.S - Guys වැඩේ හරි ගියා. ගොඩ දාගත්තා. ඔයාලගෙ උදවු වලට ගොඩාක් ස්තූතියි 🙏🙏🙏
    ------ Post added on Oct 6, 2023 at 3:10 PM
     

    Honda.putha

    Well-known member
  • Dec 26, 2017
    17,242
    29,818
    113
    Thank you Guys - wede hari giya.

    ne mchn mama IP eka change krla demme. thank you broo

    P.S - Guys වැඩේ හරි ගියා. ගොඩ දාගත්තා. ඔයාලගෙ උදවු වලට ගොඩාක් ස්තූතියි 🙏🙏🙏
    ------ Post added on Oct 6, 2023 at 3:10 PM
    mokakda wela thibbe?
     

    හෙළයෙක්

    Well-known member
  • Apr 26, 2014
    48,460
    98,390
    113
    Thank you Guys - wede hari giya.

    ne mchn mama IP eka change krla demme. thank you broo

    P.S - Guys වැඩේ හරි ගියා. ගොඩ දාගත්තා. ඔයාලගෙ උදවු වලට ගොඩාක් ස්තූතියි 🙏🙏🙏
    ------ Post added on Oct 6, 2023 at 3:10 PM
    හදාගත්ත විදිය කියන්න ඉතින්. :love::love:
     

    DevOps_Boy

    Active member
  • Jul 28, 2023
    238
    120
    43
    හදාගත්ත විදිය කියන්න ඉතින්. :love::love:
    මම අර මගෙ යූසර්ට අදාල පෙම් එක දාල ඊටපස්සෙ එන Error එක කියෙව්වම දැක්කේ මගෙ රිමෝට් සර්වර් එකේ rsync installවෙලා නෑ කියල. ඊටපස්සේ install කලාම හරි ගියා.