mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			881 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			881 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package machine
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"os"
 | 
						|
	"os/exec"
 | 
						|
	"strconv"
 | 
						|
 | 
						|
	"github.com/sirupsen/logrus"
 | 
						|
)
 | 
						|
 | 
						|
// CommonSSH is a common function for ssh'ing to a podman machine using system-connections
 | 
						|
// and a port
 | 
						|
func CommonSSH(username, identityPath, name string, sshPort int, inputArgs []string) error {
 | 
						|
	sshDestination := username + "@localhost"
 | 
						|
	port := strconv.Itoa(sshPort)
 | 
						|
 | 
						|
	args := []string{"-i", identityPath, "-p", port, sshDestination,
 | 
						|
		"-o", "IdentitiesOnly=yes",
 | 
						|
		"-o", "StrictHostKeyChecking=no", "-o", "LogLevel=ERROR", "-o", "SetEnv=LC_ALL="}
 | 
						|
	if len(inputArgs) > 0 {
 | 
						|
		args = append(args, inputArgs...)
 | 
						|
	} else {
 | 
						|
		fmt.Printf("Connecting to vm %s. To close connection, use `~.` or `exit`\n", name)
 | 
						|
	}
 | 
						|
 | 
						|
	cmd := exec.Command("ssh", args...)
 | 
						|
	logrus.Debugf("Executing: ssh %v\n", args)
 | 
						|
 | 
						|
	cmd.Stdout = os.Stdout
 | 
						|
	cmd.Stderr = os.Stderr
 | 
						|
	cmd.Stdin = os.Stdin
 | 
						|
 | 
						|
	return cmd.Run()
 | 
						|
}
 |