github.com/containers/podman/v4@v4.9.4/pkg/machine/ssh.go (about)

     1  package machine
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/exec"
     7  	"strconv"
     8  
     9  	"github.com/sirupsen/logrus"
    10  )
    11  
    12  // CommonSSH is a common function for ssh'ing to a podman machine using system-connections
    13  // and a port
    14  func CommonSSH(username, identityPath, name string, sshPort int, inputArgs []string) error {
    15  	sshDestination := username + "@localhost"
    16  	port := strconv.Itoa(sshPort)
    17  
    18  	args := []string{"-i", identityPath, "-p", port, sshDestination,
    19  		"-o", "IdentitiesOnly=yes",
    20  		"-o", "StrictHostKeyChecking=no", "-o", "LogLevel=ERROR", "-o", "SetEnv=LC_ALL="}
    21  	if len(inputArgs) > 0 {
    22  		args = append(args, inputArgs...)
    23  	} else {
    24  		fmt.Printf("Connecting to vm %s. To close connection, use `~.` or `exit`\n", name)
    25  	}
    26  
    27  	cmd := exec.Command("ssh", args...)
    28  	logrus.Debugf("Executing: ssh %v\n", args)
    29  
    30  	cmd.Stdout = os.Stdout
    31  	cmd.Stderr = os.Stderr
    32  	cmd.Stdin = os.Stdin
    33  
    34  	return cmd.Run()
    35  }