Release Automation

  • 1.  SSH key Creation

    Posted Sep 14, 2018 10:05 AM

    How can we create .ssh key for any user?



  • 2.  Re: SSH key Creation

    Broadcom Employee
    Posted Sep 14, 2018 11:21 AM

    Hello,

     

    I often create new keys to connect to various build/destroy systems. So I've scripted it (below). But this only sets it up for a specific user on that remote machine. I'm not sure how/if you can set it to work for any user. If that's what you need then I'd recommend discussing it with your linux/unix admin. 

     

    script: 

    #!/bin/bash

    if [[ -z $1 ]]; then {
    read -a SERVERNAME -p "servername: "
    } else {
    SERVERNAME=$1
    }
    fi

    if [[ -z $2 ]]; then {
    read -a USERNAME -p "username: "
    } else {
    USERNAME=$2
    }
    fi

     

    #echo #Step1 - run on remote server.
    #ssh $USERNAME@$SERVERNAME 'mkdir ~/.ssh'
    #echo ""

    #echo #Step2 - run on your local computer.
    if [ ! -f ~/.ssh/id_rsa ]; then
    ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -C "Key for ssh"
    fi
    #echo ""

    #echo #Step3 - run on your local computer
    chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
    #echo ""

    #echo #Step4 - run on your local computer (against the remote server)
    cat ~/.ssh/id_rsa.pub | ssh $USERNAME@$SERVERNAME 'mkdir ~/.ssh; cat - >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh'
    #echo ""

    #echo #Step5 - run on your local computer (against the remote server)
    #ssh $USERNAME@$SERVERNAME 'chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh'
    #echo ""

    #echo #Step6 - echo connection string (rather mouse clicks than type :))
    #echo ""
    echo ssh $USERNAME@$SERVERNAME
    #echo ""

     

     

    Regards,

    Gregg



  • 3.  Re: SSH key Creation

    Posted Sep 14, 2018 11:39 AM

    HI Gregg,

     

    i don't want to create .ssh directory, i have generated id_rsa and id_rsa.pub key for specific user.

    Now to pass the vale for this fileld i need keystore file for that user..so my question is how to generate .ssh key file 

     



  • 4.  Re: SSH key Creation
    Best Answer

    Broadcom Employee
    Posted Sep 14, 2018 12:49 PM

    So you are using the action "Run Command (SSH)"? 
    If so then I'm pretty sure (trying to recall from memory) you'll need the output of your id_rsa.pub inside of the users (specified in the username field of the action) $HOME/.ssh/authorized keys file. Specifically, this is needed on the host specified by the "Host Name" field of the action. Then, for the Keystore File field you'll put the id_rsa file on the agent machine where you'll be running this action and then:

    1. Make sure that the user id that the agent runs as has access to the id_rsa file.
    2. specify either:
      1. /absolute/path/to/and/including/the/filename/for/id_rsa
      2. /absolute/path/to/folder/containing_id_rsa

     

    Kind regards,

    Gregg