Skip to content

Instantly share code, notes, and snippets.

@vrdhn
Created December 26, 2022 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrdhn/95b90fd220b7e31043ad54b2aa034fd3 to your computer and use it in GitHub Desktop.
Save vrdhn/95b90fd220b7e31043ad54b2aa034fd3 to your computer and use it in GitHub Desktop.
Create ssh host <username>-<vmname> for libvirt
#1. Add this to TOP of ~/.ssh/config
Include ~/.ssh/config.d/*
Top means top, specifically, do not add after a Host entry
#2. This bash function:
```bash
vmssh ()
{
user=$1
vm=$2
shift
shift
ip=$(virsh domifaddr $vm | sed -n 's/.*\(192.168.122.[0-9]*\).*/\1/p')
if [ x$ip != x ]
then
mkdir -p ~/.ssh/config.d
CFG=~/.ssh/config.d/$user-$vm
echo Host $user-$vm > $CFG
echo HostName $ip >> $CFG
echo User $user >> $CFG
echo Ssh host $user-$vm created.
fi
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment