faiyaz7283 / newsetup

A script to help run some common tasks on a new machine. Tasks include setting up a machine hostname and generating an ssh key.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#### newsetup ####

image

demo

About ====

This program is a simple script designed to handle a couple of trivial tasks. The script helps setting up hostname and ssh keys quickly, a common use case when building a cluster of node servers. Once the ssh keys and proper hostnames are there, each node can be accessed individually or in a group setting. To orchestrate any repetitive tasks after that could be done much quicker, for example, using ansible or similar tools.

Backstory ====

While working on setting up a raspi cluster, I realized that I needed to generate ssh keys from each node by logging into each manually. For easy access within a local network, I also needed to set up the hostname for each. Since this is a pretty trivial but tedious task to repeat in the future, I created this script.

System requirement ====

  • bash - tested with 3.2, 4.4 and 5.
  • gnu-getopt - the getopt found on macOS will not work, you must install the gnu-getopt. brew install gnu-getopt, and make sure the gnu-getopt is in your path ahead of the existing BSD getopt.

Quick usage: ====

Log into a node and setup a hostname and generate a 521 bits ecdsa ssh key.

  • Run the script dynamically using:

    curl

    # Test with dry-run
    bash <(curl -sL tiny.cc/new-setup) -n machine01 -k ecdsa --bits 521 --dry-run
    
    # Run the code
    bash <(curl -sL tiny.cc/new-setup) -n machine01 -k ecdsa --bits 521

    wget

    # Test with dry-run
    bash <(wget tiny.cc/new-setup -o /dev/null -O -) -n machine01 -k ecdsa --bits 521 --dry-run
    
    # Run the code
    bash <(wget tiny.cc/new-setup -o /dev/null -O -) -n machine01 -k ecdsa --bits 521
  • Download the script and run manually:

    # download via curl
    curl -L tiny.cc/new-setup -o newsetup
    # or wget
    wget tiny.cc/new-setup -O newsetup
    
    chmod +x newsetup
    
    # Test with dry-run
    ./newsetup -n machine01 -k ecdsa --bits 521 --dry-run
    
    # Run the code
    ./newsetup -n machine01 -k ecdsa --bits 521

General usage ====

Setup hostname with -n | --name flag ****

When running this on a linux machine, newsetup will use the hostnamectl program to setup hostname.

hostname setup on linux.

And running on a macOS, it will use scutil program to setup hostname.

hostname setup on macOS.

Generate ssh-keys with -k | --keygen flag ****

Generating ssh keys with newsetup is fairly easy. Use the -k or --keygen flag with the following type dsa, ecdsa, ed25519 or rsa. By default, keys will be stored in the ~/.ssh directory. To change the location use the --dir flag. There is also the --bits flag available to add bit size for a particular key type. Check ssh-keygen manual for more info.

Generate a ssh key.

Get usage menu with -h | --help flag ****

For more information please check the usage menu.

Print usage menu.

Contributing ====

Any contributions or suggestions for improvements are always welcome. Please see contributing for more info.

Issues ==== Please report issues, bugs, improvements on issues page.

License ====

This project is under the MIT license.

About

A script to help run some common tasks on a new machine. Tasks include setting up a machine hostname and generating an ssh key.

License:MIT License


Languages

Language:Shell 100.0%