Skip to content

Instantly share code, notes, and snippets.

@lincolnthomas
Last active January 5, 2017 01:40
Show Gist options
  • Save lincolnthomas/272c0b2139bb5ce39887ead064573dd6 to your computer and use it in GitHub Desktop.
Save lincolnthomas/272c0b2139bb5ce39887ead064573dd6 to your computer and use it in GitHub Desktop.
Customizing newly deployed systems
When I deploy a new machine N (such as a Eucalyptus test node) I want to log into from my machine M,
here's what I do to set up passwordless logins, get my personal .bashrc on the system,
and set up the prompt so I know what machine I'm talking to.
One-time setup:
---------------
On machine M:
Add your id_rsa.pub and id_rsa files to your ~/.ssh directory.
Put these scripts in your $PATH (e.g. ~/bin):
----- rmhost.sh -----
#!/bin/bash
KNOWN=~/.ssh/known_hosts
if [ -n "$1" ] ; then
echo Removing $1 from $KNOWN
grep -v "$1" $KNOWN > $KNOWN.temp
mv -f $KNOWN $KNOWN.bak
mv -f $KNOWN.temp $KNOWN
else
echo "Usage: rmhost <hostname or IP>"
fi
----- cust.sh -----
#!/bin/bash
IP=$(ping -n 1 $1|grep 'Pinging'|cut -f2 -d '['|cut -f1 -d ']')
if [ -n "$IP" ]
then
rmhost.sh $1
rmhost.sh $IP
ssh-copy-id root@$1 && sed "s/NameHere/$2/" ~/bashrc_new > ~/bashrc_temp
scp -p ~/bashrc_temp root@$1:/root/.bashrc
else
echo "No response to ping $1, nothing done."
fi
Add this line to your .bashrc on machine M (allows shorthand "s myhost" instead of "ssh root@myhost")
function s { ssh root@$1 ; }
On M, create a file "bashrc_new" with the .bashrc you want to put on the new machine N, including these lines:
MY_HOST_FRIENDLY=cygwin
MY_HOST=$(hostname|cut -f1 -d.)
PS1='\n\[\e[32m\]\u@$MY_HOST \e[33m\]$MY_HOST_FRIENDLY\e[32m\] \t \[\e[33m\]\w\[\e[0m\]\n\$ '
For each new machine N:
-----------------------
On M, put an easy to type name in your hosts file
(On Linux: /etc/hosts)
(On Windows: c:\Windows\System32\drivers\etc\hosts)
for example:
10.111.1.69 ql44vzoo
(or use the system's real hostname instead)
On M:
$ cust.sh ql44vzoo QL_44_VPC_Zoo
Output:
---------------
Removing ql44vzoo from /home/tholinco/.ssh/known_hosts
Removing 10.111.1.69 from /home/tholinco/.ssh/known_hosts
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/tholinco/.ssh/id_rsa.pub"
The authenticity of host 'ql44vzoo (10.111.1.69)' can't be established.
ECDSA key fingerprint is SHA256:I3dLL+d6Wdh40MTEpq3xJu8e+XL6ryUafR5Xm61/QXo.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@ql44vzoo's password:
Full path required for exclude: net:[4026532200].
Full path required for exclude: net:[4026532200].
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@ql44vzoo'"
and check to make sure that only the key(s) you wanted were added.
bashrc_temp 100% 2470 50.3KB/s 00:00
---------------
Log in without password prompts from then on:
$ s ql44vzoo
Your prompt on N will look something like:
root@g-26-08 QL_44_VPC_Zoo 15:13:23 ~
#
Enjoy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment