coding-to-music / coding-to-music.github.io

https://pandemic-overview.readthedocs.io/en/latest/index.html
MIT License
2 stars 8 forks source link

doctl is able to interact with all of your DigitalOcean resources. Below are a few common usage examples #115

Open coding-to-music opened 3 years ago

coding-to-music commented 3 years ago

https://github.com/digitalocean/doctl#tutorials

doctl is able to interact with all of your DigitalOcean resources. Below are a few common usage examples. To learn more about the features available, see the full tutorial on the DigitalOcean community site.

List all Droplets on your account:

doctl compute droplet list

Create a Droplet:

doctl compute droplet create <name> --region <region-slug> --image <image-slug> --size <size-slug>

Assign a Floating IP to a Droplet:

doctl compute floating-ip-action assign <ip-addr> <droplet-id>

Create a new A record for an existing domain:

doctl compute domain records create --record-type A --record-name www --record-data <ip-addr> <domain-name>

doctl also simplifies actions without an API endpoint. For instance, it allows you to SSH to your Droplet by name:

doctl compute ssh <droplet-name>

By default, it assumes you are using the root user. If you want to SSH as a specific user, you can do that as well:

doctl compute ssh <user>@<droplet-name>

Tutorials

Set permissions if needed

sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/*
sudo chown -R ${USER} ~/.ssh/
sudo chgrp -R ${USER} ~/.ssh/

if you get this error regarding .ssh/known_hosts:

Failed to add the host to the list of known hosts

Then simply delete the known_hosts file, and re-run your ssh. This will regenerate the known_host file with appropriate permissions, and add the remote host you are trying to ssh into to this file.

Communicating between droplets

chmod 600 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/id_rsa

doctl compute ssh tmc@docker-ubuntu-s-1vcpu-2gb-nyc1-01
doctl compute ssh root@docker-ubuntu-s-1vcpu-2gb-nyc1-01

doctl compute ssh tmc@docker-ubuntu-s-4vcpu-8gb-nyc1-01
doctl compute ssh root@docker-ubuntu-s-4vcpu-8gb-nyc1-01

wget https://github.com/coding-to-music/dotfiles/raw/master/.bash_aliases
coding-to-music commented 3 years ago

How to Enable SSH Password Authentication

https://serverpilot.io/docs/how-to-enable-ssh-password-authentication/

Some server providers, such as Amazon EC2 and Google Compute Engine, disable SSH password authentication by default. That is, you can only log in over SSH using public key authentication.

SFTP is a protocol that runs over SSH, so this means SFTP using passwords will not work by default when SSH password authentication is disabled.

To enable SSH password authentication, you must SSH in as root to edit this file:

/etc/ssh/sshd_config

Then, change the line

PasswordAuthentication no

to

PasswordAuthentication yes

After making that change, restart the SSH service by running the following command as root:

sudo service ssh restart

Enable Logging In as root

Some providers also disable the ability to SSH in directly as root. In those cases, they created a different user for you that has sudo privileges (often named ubuntu). With that user, you can get a root shell by running the command:

sudo -i

If you instead want to be able to directly SSH in as root, again edit this file:

/etc/ssh/sshd_config

And change the line

PermitRootLogin no

to

PermitRootLogin yes

After making that change, restart the SSH service by running the following command as root:

sudo service ssh restart

If you enable this setting, don't forget to set a strong password for root by running the command.

sudo passwd root
coding-to-music commented 3 years ago

https://www.digitalocean.com/community/tutorials/how-to-use-doctl-the-official-digitalocean-command-line-client

https://github.com/digitalocean/doctl/releases

https://github.com/digitalocean/doctl#arch-linux

https://github.com/digitalocean/doctl#tutorials

https://github.com/digitalocean/doctl#using-a-package-manager-preferred

coding-to-music commented 3 years ago

Install and Use doctl to manage DigitalOcean resources

https://techviewleo.com/how-to-manage-digitalocean-with-doctl/The doctl command line tool enables you to interact with the DigitalOcean API via the command line. It supports most functionality found in the control panel. You can create, configure, and destroy DigitalOcean resources like Droplets, Kubernetes clusters, firewalls, load balancers, database clusters, domains, and more.

In other articles we will cover creation and deletion of resources and applications deployed on DigitalOcean cloud platform.

Step 1: Install doctl on macOS and Linux There are many ways from which doctl can be installed on macOS and Linux distributions.

Install doctl on macOS using Homebrew: brew install doctl Install doctl on Arch Linux sudo pacman -S doctl Install doctl on all other Linux distributions from binary files: Download archive file.

64 bit Linux OS

curl -s https://api.github.com/repos/digitalocean/doctl/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep linux-amd64 | wget -qi -

32 bit Linux system

curl -s https://api.github.com/repos/digitalocean/doctl/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep linux-386 | wget -qi - Once downloaded extract the file using the command below.

64-bit

tar xvf doctl-*-linux-amd64.tar.gz

32-bit

tar xvf doctl-*-linux-386.tar.gz Move extracted binary file to /usr/local/bin directory

sudo mv doctl /usr/local/bin Confirm doctl command is available in your bash shell and executable.

$ doctl version doctl version 1.54.0-release Git commit hash: a901a72 Step 2: Generate DigitalOcean Access Token The DigitalOcean API allows you to manage Droplets and resources within the DigitalOcean cloud in a simple, programmatic way using conventional HTTP requests. The endpoints are intuitive and powerful, allowing you to easily make calls to retrieve information or to execute actions.

To generate the token login to DigitalOcean portal and head over to API > Applications & API > Tokens/Keys > Generate New Token.

Step 3: Authenticating with DigitalOcean Copy Token ID generated in step 2 and initiate the authentication with DigitalOcean by running the following command in your terminal. Enter DigitalOcean access token when prompted.

$ doctl auth init Please authenticate doctl for use with your DigitalOcean account. You can generate a token in the control panel at https://cloud.digitalocean.com/account/api/tokens

Enter your access token: Validating token... OK The commands will initialize doctl to use a specific account. A confirmation message will be given once the credentials are accepted. If the token doesn’t validate, make sure you copied and pasted it correctly. Validating token: OK The default config file will be located in:

macOS: ${HOME}/Library/Application Support/doctl/config.yaml Linux: ${XDG_CONFIG_HOME}/doctl/config.yaml Windows: %APPDATA%\doctl\config.yaml Confirm doctl is working by retrieving your API usage and the remaining quota:

$ doctl account ratelimit Limit Remaining Reset 5000 4997 2021-01-04 11:33:09 +0300 EAT Step 4: Doctl usage examples Listing billing histories:

$ doctl billing-history list Retrieving your account balance

$ doctl balance get Month-to-date Balance Account Balance Month-to-date Usage Generated At 8.49 0.00 8.49 2021-01-04T06:02:07Z List running droplets

$ doctl compute droplet list

Filter output

$ doctl compute droplet list --format Name,Memory,VCPUs,Disk,PrivateIPv4,PublicIPv4,Image,Status,Region List available distribution images

$ doctl compute image list-distribution ID Name Type Distribution Slug Public Min Disk 54203610 16.04.6 (LTS) x32 snapshot Ubuntu ubuntu-16-04-x32 true 20 59416024 12.1 ufs x64 snapshot FreeBSD freebsd-12-x64 true 20 65416372 v1.5.6 snapshot RancherOS rancheros true 20 69440038 10 x64 snapshot Debian debian-10-x64 true 15 69440042 9 x64 snapshot Debian debian-9-x64 true 15 69452245 11.4 zfs x64 snapshot FreeBSD freebsd-11-x64-zfs true 15 69500386 11.4 ufs x64 snapshot FreeBSD freebsd-11-x64-ufs true 15 69535713 7.6 x64 snapshot CentOS centos-7-x64 true 20 70639049 32 x64 snapshot Fedora fedora-32-x64 true 15 72061309 18.04 (LTS) x64 snapshot Ubuntu ubuntu-18-04-x64 true 15 72067660 20.04 (LTS) x64 snapshot Ubuntu ubuntu-20-04-x64 true 15 72067667 16.04 (LTS) x64 snapshot Ubuntu ubuntu-16-04-x64 true 15 72181180 20.10 x64 snapshot Ubuntu ubuntu-20-10-x64 true 15 72465092 33 x64 snapshot Fedora fedora-33-x64 true 15 72791873 12.2 ufs x64 snapshot FreeBSD freebsd-12-x64-ufs true 20 72794028 12.2 zfs x64 snapshot FreeBSD freebsd-12-x64-zfs true 15 72855737 12.1 ufs x64 snapshot FreeBSD freebsd-12-1-x64-ufs true 20 72903235 12.1 zfs x64 snapshot FreeBSD freebsd-12-1-x64-zfs true 20 74885442 8.3 x64 snapshot CentOS centos-8-x64 true 15 When doing automation of droplets creation you’ll often use the image slug names.

To all list images on your account including backups use:

$ doctl compute image list List your database clusters:

$ doctl databases list Delete Droplet

$ doctl compute droplet delete <droplet-id|droplet-name>... [flags]

Example

$ doctl compute droplet delete -f freebsd12 List available compute sizes

$ doctl compute size list List valid compute resources regions

$ doctl compute region list Slug Name Available nyc1 New York 1 true sfo1 San Francisco 1 false nyc2 New York 2 false ams2 Amsterdam 2 false sgp1 Singapore 1 true lon1 London 1 true nyc3 New York 3 true ams3 Amsterdam 3 true fra1 Frankfurt 1 true tor1 Toronto 1 true sfo2 San Francisco 2 true blr1 Bangalore 1 true sfo3 San Francisco 3 true Create a droplet

$ doctl compute droplet create ... [flags]

Examples

$ doctl compute droplet create --ssh-keys --image freebsd-12-x64-zfs --size s-1vcpu-1gb --region nyc1 freebsd12 Delete droplet:

$ doctl compute droplet delete -f freebsd12