jenkins - can't ssh to remote server (key - permission denied) but works from cli

前端 未结 5 1235
孤独总比滥情好
孤独总比滥情好 2021-01-06 12:40

I have Jenkins running on my local machine trying to figure out remote ssh problem I\'m having on a server. I\'m getting this permission denied error which indicates a probl

相关标签:
5条回答
  • 2021-01-06 13:19

    Jenkins run shell scripts is slight different with cmd line on environment

    there are some environment difference in your case, which we didn't notice. like initial script, path setting.

    besides the method provided by @coffeebreaks, try below

    • check the system environment, like show command env
    • write above steps into bash scripts and run the scripts both in cmd line and jenkins jobs
    • use another user instead of your initial user who starts jenkins instance
    0 讨论(0)
  • 2021-01-06 13:20

    Multiple reasons could cause this behavior, like key caching with agent / keychain manager, etc.

    I would suggest to use the -v argument to compare the 2 outputs:

    ssh -v -i /Users/jgoodwin/.ssh/id_rsa remoteuser@server
    

    This will let you compare what is going in in a more verbose way. If you still cannot solve it, please post your verbose outputs to compare.

    Note: you can add up to 3 -v arguments for increased verbosity.

    Updated:

    @JasonG From what I see the details of the failure are:

    debug1: Offering RSA public key: /Users/jgoodwin/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: key_parse_private_pem: PEM_read_PrivateKey failed debug1: read PEM private key done: type debug1: read_passphrase: can't open /dev/tty: Device not configured

    It looks like your key has a passphrase and the passphrase cannot be entered because we are not in an interactive shell. The command line from your standard shell may benefit from the Keycahin which would 'type the passphrase' for you.

    If you could generate the same verbosity for your successful command so that we could compare...

    0 讨论(0)
  • 2021-01-06 13:25

    Check whether the home directory is encrypted : http://gopukrish.wordpress.com/2013/04/24/ssh-cant-connect-authentications-that-can-continue-publickeygssapi-keyexgssapi-with-micpassword/

    0 讨论(0)
  • 2021-01-06 13:32

    In my situation, I was using a keychain (as @coffeebreaks suggested) which was being setup when I sourced in the jenkins user .bashrc file. Unfortunately, the jenkins backend doesn't seem to source this file like a standard shell login does.

    The solution was to add the following code prior to the scp call in the Jenkins pipeline:

    . ~/.bashrc
    
    0 讨论(0)
  • 2021-01-06 13:42

    Looks like the public key is missing under /Users/jgoodwin/.ssh/id_rsa.pub instead id_rsa there.... can you pls double check and provide permission 600 to that file and re-run your jenkins job

    debug1: Offering RSA public key: /Users/jgoodwin/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: key_parse_private_pem: PEM_read_PrivateKey failed

    0 讨论(0)
提交回复
热议问题