This link has been bookmarked by 125 people . It was first bookmarked on 18 Jun 2007, by Joel Liu.
-
19 Aug 13
-
12 Oct 10
-
04 May 09
Rodrigo de OliveiraDicas de uso avançado do shell Linux (bash principalmente)
-
27 May 08
-
08 May 08
-
07 May 08
-
22 Apr 08
-
12 Apr 08
-
22 Mar 08
-
28 Jan 08
-
01 Jan 08
-
28 Dec 07
-
20 Nov 07
-
09 Nov 07
-
06 Oct 07
-
22 Sep 07
-
08 Sep 07
-
16 Jul 07
-
04 Jul 07
-
03 Jul 07
-
6. Add Your Public Key to Remote Machines the Easy Way
In order to perform key based logins to a new machine, you need to get a copy of a public key to the remote machine yourself. Sure, you could do this manually – which gets a bit boring after a while (why doesn’t SSH have an authorized_keys.d anyway?), but why waste time when SSH comes with it the tool to do it?
Just run:ssh-copy-id -i .ssh/id_rsa.pub hostname
After being prompted to enter your password for the last time, SSH will say:
Now try logging into the machine, with “ssh ‘hostname’”, and check in:.ssh/authorized_keys
to make sure we haven’t added extra keys that you weren’t expecting.
Try it. No more passwords!
-
2. Parallelize Your Loops
Almost every Linux network administrator knows the power of the for loop: the way to do something for one, one hundred or one thousand users, files, machines, processes, or whatever else. Most people set their loops in sequence – so that each jobs is finished before moving onto the next.
But the jobs command can be used to background each loop, so you don’t have to wait for it to complete before continuing with the next.Here’s an example running an apt-get update:
for HOST in $(< ListOfHosts); do ssh $HOST ’sudo apt-get update’ & done
Maybe you need a bunch of SSH tunnels running simultaneously:
for HOST in $(< ListOfHosts); do ssh -C -N -R 80:localhost:80 $HOST & done
Sometimes you probably don’t want to see all the output as it happens – in that case, save a file on each machine and use another loop to collect it later.
Benefit: Saving a metric shitload (2/3rd of an imperial shitload) of time waiting on stuff to finish
Works in: any currently supported Linux
Drawbacks: Bash probably has some limits of the amount of concurrent jobs. But I’ve yet to run into them.
-
-
01 Jul 07
-
28 Jun 07
-
25 Jun 07
-
24 Jun 07
-
22 Jun 07
-
21 Jun 07
-
20 Jun 07
-
19 Jun 07
-
18 Jun 07
-
17 Jun 07
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.