Showing posts with label Shell. Show all posts
Showing posts with label Shell. Show all posts

Friday, 29 April 2016

ssh without passwords

One thing I’ve done quite a few times, but always have to look up how to do it as it’s a “do it once, then forget it” kind of thing.

Here’s how to do it:

  • On the client machine, run ssh-keygen
  • Once the key is created, run ssh-copy-id remoteuser@remotehost
You’ll be asked for the remoteuser password, the key is copied across, and ... that is it. You can now ssh remoteuser@remotehost and never need a password.

Wednesday, 27 January 2016

Deleting Files

Sometimes, you want to delete all but one of a file from a folder. Using a GUI, it’s fairly straightforward—Ctrl-A will normally select the files, Ctrl-click on the file you don’t want to delete to de-select it, and ... delete.

What about from the command line? Sometimes (like on a headless server or when you ssh into the computer at work) you need to do the same thing from a shell. Here’s the best way I’ve found to do that:

find . ! -name 'file.txt' -type f -exec rm -f {} +

This will delete every file from the current directory except file.txt.  Nice and easy.