You are here: Advanced Concepts > Creating DynaCenter Software Components > Sample Linux Components > Creating a Component to Add an SSH Key

Creating a Component to Add an SSH Key

This component adds a public SSH key to the authorized_keys file on a deployed server so that you can gain secure access to a newly deployed server.

Use Case

You need authenticated access to a server immediately after an image is deployed to a target server.

Create the Component

Tip: Sample Script to Create the SSH Key Component provides a sample script that shows how to automate the manual process outlined in this topic.

Procedure

As a root user on the MWS, complete the following procedure:

  1. Create a component working directory.

    Example: mkdir /root/components

  2. In the components directory, create the directory structure for this component.

    Example: mkdir -p ssh-key/root/root/.ssh

  3. In the components directory, type the following command to change the access permissions of the .ssh directory:
    chmod 700 ssh-key/root/root/.ssh
  4. In the components directory, copy the public ssh key you want to distribute in to the ssh-key/root directory.

    cp <your_public_key> ssh-key/root/mypubkey

  5. In the ssh-key directory, create a shell-compatible postprovision script to cat the distributed key to the authorized_keys file.
  6. In the ssh-key directory, type the following command to change the access permissions of the script:
    chmod 0500 postprovision
  7. In the components directory, type the following to create the component archive:
    msa --name='add-ssh-key' \
    --desc='add public ssh key' \
    --ostype='*_Linux-*_*_*-*' \
    ssh-key
    

    Where:

    Options--nameComponent name; if not specified, the pathname is used
    --descHelpful description for the component
    --ostype

    Operating system of the component and the image it will be applied to

    Note: Each component must have the same os-type as the image that will use it or the deploy will not complete successfully. The dccmd list ostypes command lists valid operating system types. The format supports wildcards; however, it is always best to select the most specific value possible.

    Argument--pathnameComponent directory where the component control files should be placed
  8. In the components directory, type the following to convert the archive into a component:

    rinstallsnapshot \
    --description='add public ssh key' \
    --ostype='*_Linux-*_*_*-* ' \
    add-ssh-key \
    add-ssh-key.tar \
    default
    

    Where:

    Options --description Helpful description for the component
    --os-type

    Operating system of the component and the image it will be applied to

    Note: Each component must have the same os-type as the image that will use it or the deploy will not complete successfully.

    Arguments name Descriptive name for the software component
    source Component archive used for the component
    repository

    Repository that will hold the component

    Note: This should always be default.

  9. Add the component statement to the deploy profile that will be used with the image deploy task.

    Example:  

    #Deploy ssh key component
    component add-ssh-key
    

 

© Copyright Racemi Incorporated 2017. All rights reserved.