Example:
ssh username@host "echo $HOSTNAME && sudo somecommand && cat somecommand.log"
There's probably a better way to do this, but in a pinch I can fix a problem on dozens of machines just by altering the host string.
Example:
ssh username@host "echo $HOSTNAME && sudo somecommand && cat somecommand.log"
There's probably a better way to do this, but in a pinch I can fix a problem on dozens of machines just by altering the host string.
for host in h-abc h-def h-ghi h-jkl h-mno h-pqr h-stu h-vwx h-yza;
do
ssh -l root $host "hostname; echo "1.1.1.1 server" >> /etc/hosts";
done
This would iterate over hosts (h-abc .. h-yza) and run the commands "hostname; echo "1.1.1.1 server" >> /etc/hosts". Or maybe use a for loop and scp to push the files out and then run md5 to verify they are correct. It was a hack but useful for a small set of machines.ps. if you are interested in learning about puppet, I have put together a screencast about it @ http://sysadmincasts.com/episodes/8-learning-puppet-with-vag...
for host in ... ; do ssh -l root $host "..." & done; wait
and it's very parallel. All that key exchange takes a while, so it's not ridiculously fast, but it's pretty good. If you've got ControlMaster set up already to be per-host, this might very well be very fast the second time. % (cd /foo; tar cpf - .) | ssh bar \(cd /baz\; tar xpf -\)
Or: % cat ~/.ssh/id_rsa.pub | ssh bar tee -a .ssh/authorized_keysSo basically, you get :
(local) (remote)
stdin -> ssh ssh -> stdout
Hope that helps. tar cj $bigdir | ssh host 'tar xj'
That creates a tar.bz2 archive on your machine, sends it over ssh to the remote host, where it's unpacked. Ad hoc compressed and encrypted file transfers made easy. rsync -az $bigdir host:$bigdirOf course, ssh also gives you the output of the remote process, so you can put an ssh command in the middle of a pipeline. My day to day life no longer involves interacting with lots of remote Unix systems, but when it did, it was really, really useful.
% (cd /foo && tar cpf - .) | ssh bar '(cd /baz && tar xpf -)'
or explore something like: % rsync -aSHx --update --delete -e ssh /foo/ user@bar:baz/. ssh-copy-id - install your public key in a remote machine’s authorized_keys"typing a password on your local machine once, then using a secure identity to login to several remote machines without having to retype your password by using an ssh key agent. This is awesome. "
Sounds awesome, but I really didn't understand what he means. Is he talking about using a certificate (-i option) to log in ?
So you'll need to create an SSH cert first:
ssh-keygen -b 4096 -t rsa -C "$USER created on $(hostname)" -f $USER.key
Keep the private key, that's essential you keep this safe as it's literally your key to access any servers you do the next step for.On each server SSH, append your public key to the of /home/$USER/.ssh/authorized_keys (creating the file if it doesn't exist). It must be the public key!
There'll be better guides online for this stuff so I suggest you have a read through them before blindly pasting the stuff I've posted into your terminal. But it's all quite simple stuff once you've grasped the difference between a public and private key (if you weren't already aware - you may well be)
"ssh-ebT23030"
Meaning that anyone with root access who know the other machines that someone is accessing as well as their username can access those machines.
I've seen cases where in abnormally terminated sessions that file stays around instead of getting deleted when the session ends.
Piped tar commands do, but are generally inferior to rsync (at least if you ever need to copy more than once). I believe I've heard (here) that piped tar commands can be useful for the first sync (possibly better compression, no overhead of file checksums), then rsync thereafter.
nohup time whatever >whatever.out &
because so many programs behave differently when attached to a tty (like prompting for input) and I just want a plain text log that says when it succeeded or where it blew up.