Just another tech enthusiast.
8 stories
·
0 followers

Have a lot of Droplets? Use do-ssh-alias for easier SSH access

2 Shares
Have a lot of Droplets? Use do-ssh-alias for easier SSH access

If you have a lot of Droplets on your account, you probably agree that it's hard to keep track of all of them—especially if you create new ones and destroy them frequently for one-off workloads. A common pain point is having to look up a Droplet's IP address when needing to SSH into it.

I created do-ssh-alias to help address that. Let's look at how it can help.

What is do-ssh-alias?

Let's assume you have a Droplet named shiny-blog. Usually you would look up its IP address and then SSH into it like so:

ssh username@1.2.3.4  

What if, instead, you could simply run the following command?

ssh shiny-blog  

This is where do-ssh-alias comes in. It creates SSH aliases for all your Droplets at once so you can easily SSH in, without having to worry about what user or hostname to use.

It is especially useful if your Droplets' hostnames are FQDNs (e.g. shiny.example.com) that don't point directly to the Droplets' IP addresses. One example is using Cloudflare in front of your website, so your domain name resolves to a Cloudflare server instead of your Droplet.

How do I use it?

do-ssh-alias depends on the programs jq and doctl. The first step is installing jq and installing doctl. Linked are the installation instructions for each program. Once you install doctl, log it in to your DigitalOcean account.

With the dependencies taken care of, let's now install do-ssh-alias. You can either download the script from GitHub or use the command line:

wget https://do.co/do-ssh-alias  

It's always a good idea to review any scripts you download from the internet before executing them.

Once you have the file on your computer, update its permissions to allow it to be executed:

chmod +x do-ssh-alias  

It's now ready to use. To generate aliases for your Droplets, run:

./do-ssh-alias > ~/.ssh/do_aliases

This will run do-ssh-alias and save the results in the file ~/.ssh/do_aliases.

Finally, update your ssh config to actually use the file with the aliases. Open ~/.ssh/config in a text editor and add the following line at the top:

Include do_aliases  

That's it. You can now SSH to your Droplets using their hostnames! Any time you create or remove Droplets, simply run it again to update the configuration.

What else can it do?

do-ssh-alias only generates SSH aliases, but it accepts a few options for some flexibility:

  • -u: Pass your SSH username like -u sammy to automatically use it for all hosts.
  • -i: To ignore certain Droplets and not create aliases for them, pass their hostnames like -i ignored-hostname-1 -i ignored-hostname-2.
  • -s: Pass a suffix with the -s option to generate additional aliases with that suffix stripped. For example, if your Droplet's hostname is shiny.example.com passing -s .example.com will generate an alias for ssh shiny in addition to ssh shiny.example.com.

Below is an example of using all three options.

Show me an example, please!

Let's assume you have the following Droplets on your account:

  • droplet1
  • droplet2.domain.com
  • droplet3.domain.com

Running:

do-ssh-alias -u sammy -i droplet1 -s .domain.com  

will generate aliases for:

  • ssh droplet2.domain.com
  • ssh droplet2
  • ssh droplet3.domain.com
  • ssh droplet3

all using the username sammy to log in. The SSH config will look like so:

Host droplet2.domain.com droplet2  
    Hostname Droplet2-IP
    User sammy

Host droplet3.domain.com droplet3  
    Hostname Droplet3-IP
    User sammy

Resources

Here are some resources you may find useful:

Note: doctl itself provides similar functionality through the doctl compute ssh command which allows you to SSH into a Droplet using its ID or name. The main difference is that doctl looks up the Droplet's IP address using the DigitalOcean API every time you run it, while do-ssh-alias generates a static config file that ssh reads. You might prefer do-ssh-alias if:

  • you want an SSH config that can be copied to other computers without having to install doctl or store your API token on them; or
  • want to avoid the added latency of doctl's API request.
Read the whole story
rakhesh
1439 days ago
reply
United Kingdom
Share this story
Delete

UTC is enough for everyone... Right?

2 Shares
Programming time, dates, timezones, recurring events, leap seconds... Everything is pretty terrible. The common refrain in the industry is Just use UTC! Just use UTC! And that's correct... Sort of. But if you're stuck building software that deals with time, there's so much more to consider. It's time... To talk about time.

This is one of the best articles - experiences? - I've ever read. It's funny, well-written, deeply informative, and covers everything from programming with time, to time and UI design, to time and accessibility. This is simply an amazing piece of work.

Read the whole story
rakhesh
2145 days ago
reply
United Kingdom
Share this story
Delete

Hiawatha and the GDPR

1 Share

Within a few days, the General Data Protection Regulation (GDPR) will take effect. Hiawatha collects and stores the visitor's IP addresses. Since an IP address is personal data, it's possible that you must comply to the GDPR for that. One of the first things you must to is to determine the lawfulness of the processing. Recital 49 of the GDPR states that ensuring network and information security constitutes a legitimate interest, as defined in article 6 (1) lit f.

So, in normal English, you are allowed to store the IP address of a visitor for the purpose of securing your webserver. However, you still have to comply with the rest of the GDPR. That means that you should not keep IP addresses for longer that necessary (use logfile rotation), secure the logfiles well, be clear to your visitors what information your collect, for what reason and how you keep that information (privacy policy on your website) and stick to that.

The visitor, or the data subject to speak in legal terms, has the right to see what information about him/her is being processed. Of course, that person has to prove that he/she is indeed the owner/user of that IP address and also for what period of time. Otherwise, you have a data breach. That it's very hard or even practically impossible to prove that, is not your problem.

It’s easy to make plausible that the information in the system, exploit and garbage logfile is necessary for information security. It might be a bit more tricky for the information in the access and error logfile. You can use Hiawatha’s AnonymizeIP option to deal with that. The manual contains an error. It says that it also anonymizes IP's sent to the Hiawatha Monitor, but the Monitor doesn't collect IP addresses. It used to do so in an earlier version, but I forgot to remove that remark from the manual.

After reading all this, you may ask yourself: do I really need to go through all this hustle for just a personal website? No, article 2 (2) lit c clearly states that the GDPR does not apply to the processing of personal information in the course of a purely personal activity.

Read the whole story
rakhesh
2146 days ago
reply
United Kingdom
Share this story
Delete

★ Public Service Announcement: You Should Not Force Quit Apps on iOS

6 Comments and 12 Shares

The single biggest misconception about iOS is that it’s good digital hygiene to force quit apps that you aren’t using. The idea is that apps in the background are locking up unnecessary RAM and consuming unnecessary CPU cycles, thus hurting performance and wasting battery life.

That’s not how iOS works. The iOS system is designed so that none of the above justifications for force quitting are true. Apps in the background are effectively “frozen”, severely limiting what they can do in the background and freeing up the RAM they were using. iOS is really, really good at this. It is so good at this that unfreezing a frozen app takes up way less CPU (and energy) than relaunching an app that had been force quit. Not only does force quitting your apps not help, it actually hurts. Your battery life will be worse and it will take much longer to switch apps if you force quit apps in the background.

Here’s a short and sweet answer from Craig Federighi, in response to an email from a customer asking if he force quits apps and whether doing so preserves battery life: “No and no.”

Here, from the official support document on forcing applications to close, is Apple’s own advice on when to use this feature:

When you double-click the Home button, your recently used apps appear. The apps aren’t open, but they’re in standby mode to help you navigate and multitask. You should force an app to close only when it’s unresponsive.

Update: MacDailyNews quotes a 2010 email from Steve Jobs:

Just use [iOS multitasking] as designed, and you’ll be happy. No need to ever quit apps.

Just in case you don’t believe Apple’s senior vice president for software, Apple’s own official support documentation, or Steve Jobs, here are some other articles pointing out how this habit is actually detrimental to iPhone battery life:

This thing about force quitting apps in the background is such a pernicious myth that I’ve heard numerous stories from DF readers about Apple Store Genius Bar staff recommending it to customers. Those “geniuses” are anything but geniuses.

It occurs to me that one of the best examples proving that this notion is wrong (at least in terms of performance) are YouTube “speed test” benchmarks. There’s an entire genre of YouTube videos devoted to benchmarking new phones by running them through a series of apps and CPU-intensive tasks repeatedly, going through the loop twice. Once from a cold boot and the second time immediately after the first first loop. Here’s a perfect example, pitting a Samsung Galaxy S8 against an iPhone 7 Plus. Note that no apps are manually force quit on either device. The iPhone easily wins on the first loop, but where the iPhone really shines is on the second loop. The S8 has to relaunch all (or at least almost all) of the apps, because Android has forced them to quit while in the background to reclaim the RAM they were using. On the iPhone, all (or nearly all) of the apps re-animate almost instantly.

In fact, apps frozen in the background on iOS unfreeze so quickly that I think it actually helps perpetuate the myth that you should force quit them: if you’re worried that background apps are draining your battery and you see how quickly they load from the background, it’s a reasonable assumption to believe that they never stopped running. But they do. They really do get frozen, the RAM they were using really does get reclaimed by the system, and they really do unfreeze and come back to life that quickly.1

An awful lot of very hard work went into making iOS work like this. It’s a huge technical advantage that iOS holds over Android. And every iPhone user in the world who habitually force quits background apps manually is wasting all of the effort that went into this while simultaneously wasting their own device’s battery life and making everything slower for themselves.

This pernicious myth is longstanding and seemingly will not die. I wrote about at length back in 2012:

Like with any voodoo, there are die-hard believers. I’m quite certain that I am going to receive email from people who will swear up-and-down that emptying this list of used applications every hour or so keeps their iPhone running better than it would otherwise. Nonsense.

As Fraser mentions, yes, there are exceptional situations where an app with background privileges can get stuck, and you need to kill that app. The argument here is not that you should never have to kill any app using the multitasking switcher — the argument is that you don’t need to do it on a regular basis, and you’re not making anything “better” by clearing the list. Shame on the “geniuses” who are peddling this advice.

And don’t even get me started on people who completely power down their iPhones while putting them back into their pockets or purses.


  1. The other contributing factor to believing that force quitting is good for your iPhone are the handful of apps that have been found to be repeated abusers of loopholes in iOS, such that they really do continue running in the background, wasting battery life. Most infamously, Facebook was caught playing silent audio tracks in the background to take advantage of APIs that allow audio-playing apps to play audio from the background. They called it a “bug”. In those cases force-quitting the apps really did help, and I see no reason to trust Facebook. So if you want to keep force quitting Facebook, go right ahead. But don’t let one bad app spoil the whole barrel. The Battery section in the iOS Settings app can show you which apps are actually consuming energy in the background — tap the clock icon under “Battery Usage” and don’t force quit any app that isn’t a genuine culprit. ↩︎

Read the whole story
popular
2461 days ago
reply
rakhesh
2461 days ago
reply
United Kingdom
Share this story
Delete
5 public comments
walokra
2437 days ago
reply
Good point.
tiglathpalasar
2459 days ago
reply
IOS really sucks.
johnnysimmons33
2459 days ago
reply
Noted! well we are all just clueless idiots I guess bc nobody ever told me that I should just leave my 800+ apps running and my phone will be better for it!
Nob Hill, San Francisco
arnabocean
2458 days ago
Well, most of us come from a background of operating systems where *we* the users are expected to think about how the *software* should operate and handle memory. That's backwards, and yet we take a long time to be comfortable with the idea that an operating system should be mature and sophisticated enough to handle the "background" logistics. :-)
jhamill
2462 days ago
reply
While it might be correct that you don't need to force quit apps or power down your phone or whatever. The bigger problem here, to me, is the people who feel the need to tell other people that they're using the device wrong. It's my device, I'll use it how I want, no matter what you say.

Quit wasting time writing the you're using your device wrong stories.
California
arnabocean
2462 days ago
There's two sides to this, isn't it. There's one group of people who do things thinking "this helps me with whatever". With this, you can demonstrate that their actions don't achieve their goals, and then they change their actions. The other group of people are different. For example, they might choose to open Safari, type "google" into the search bar, click the first link to "google.com", type into the search bar in google, and *then* see their actual search results. You might show them there's a better way, and they might say, "well this is my phone, and I'll use it how I want, no matter what you say". Well, they're right, and in that case, you just walk away knowing they're idiots. But it doesn't mean you stop showing other people that there is indeed a better way. :-)
tewha
2461 days ago
I have no problem being told I'm doing something wrong and could be doing it in a way that's better and easier, but I guess you do? That's unfortunate, but don't worry: Nobody will ever force you to be rational. You can use the device however you like. Just don't be surprised when there's people pointing out it's not only unhelpful but actually counter productive. And try not to get angry; they have every right to talk about such things.
jhamill
2461 days ago
Congratulations everyone, we've "Well, actually" on the internet. That's just as good as the 'you're doing it wrong' article.
tewha
2461 days ago
And congratulations, jhamill, for being an ignorant and aggressive asshole.
jhamill
2461 days ago
Sure, okay @tewha I'm not the one calling people assholes on the internet but, you do you.
tdknox
2462 days ago
reply
The one app I do force quit regularly is Waze, because if you don't it continuously monitors your location even when you're not driving or using it.

iOS 11 makes that much more clear with a giant blue bar at the top of the screen 'Waze is using your location', which miraculously goes away after I punt Waze.

But otherwise, Gruber is completely correct.
San Jose, CA
Repton
2460 days ago
Go go settings ➡️ privacy ➡️ location services, and set it to only have access when you are using the app?
neilcar
2457 days ago
The problem with that is, when I'm actually navigating, I may be using other apps (to play music, for example). If I have Waze only use location services when the app is in the foreground, it isn't going to work well. Like tdnox, I force-quit Waze when I'm done with it.

Mozilla Delivers “the Best Firefox Ever”

1 Share
Mozilla Delivers "the Best Firefox Ever"

This week, Mozilla announced Firefox 54, which provides multi-processing capabilities for "remarkably" improved performance and memory usage.

The post Mozilla Delivers “the Best Firefox Ever” appeared first on Thurrott.com.

Read the whole story
rakhesh
2497 days ago
reply
United Kingdom
Share this story
Delete

“Relayd and Httpd Mastery” is out!

1 Share

I’m pleased to say that Relayd and Httpd Mastery is now available in print and ebook.

Sponsors should be able to log into their accounts and download the updated book.

I don’t have a print copy of the book in my hands yet, but they’re on the way. Unless something goes wrong, I’ll a) have copies mailed to all the print sponsors before I leave for BSDCan, and b) have a few copies for BSDCan.

Now to put in some quantity time for the third edition of Absolute FreeBSD before BSDCan…

Read the whole story
rakhesh
2519 days ago
reply
United Kingdom
Share this story
Delete
Next Page of Stories