Created
December 26, 2022 11:28
-
-
Save vrdhn/95b90fd220b7e31043ad54b2aa034fd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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