Repository: containers/podman
Pull request #21171 (2024-01-05 12:58:20)

Refactor: replace StringInSlice with slices.Contains
This PR refactors code to use [slices.Contains](https://pkg.go.dev/golang.org/x/exp/slices#Contains) instead of `StringInSlice`, [slices.Index](https://pkg.go.dev/golang.org/x/exp/slices#Index) instead of `IndexOfStringInSlice`.

Other changes:
- remove `util.StringInSlice`and `util.IndexOfStringInSlice` from `pkg/util` package;
- remove `utils.StringInSlice` from `test/utils` package;
- remove `test.StringInSlice` from `pkg/bindings/test` package.

When we upgrade to Go 1.21, `golang.org/x/exp/slices` will be replaced by [`slices`](https://pkg.go.dev/slices) from std.

#### Does this PR introduce a user-facing change?

```release-note
None
```


openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/containers/podman/pull/21171#" title="Author self-approved">alexandear</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign [n1hility](https://github.com/n1hility) for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=containers%2Fpodman).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/containers/podman/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["n1hility"]} -->

Patch:
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 6d97ea7d65..b48b096878 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -11,7 +11,6 @@ import (
 	"github.com/containers/buildah/pkg/cli"
 	"github.com/containers/common/pkg/auth"
 	"github.com/containers/common/pkg/config"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/image/v5/transports/alltransports"
 	"github.com/containers/image/v5/types"
 	"github.com/containers/podman/v4/cmd/podman/common"
@@ -24,6 +23,7 @@ import (
 	"github.com/containers/podman/v4/pkg/util"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 	"golang.org/x/term"
 )
 
@@ -134,7 +134,7 @@ func create(cmd *cobra.Command, args []string) error {
 		if !cmd.Flags().Changed("pod") {
 			return errors.New("must specify pod value with init-ctr")
 		}
-		if !cutil.StringInSlice(initctr, []string{define.AlwaysInitContainer, define.OneShotInitContainer}) {
+		if !slices.Contains([]string{define.AlwaysInitContainer, define.OneShotInitContainer}, initctr) {
 			return fmt.Errorf("init-ctr value must be '%s' or '%s'", define.AlwaysInitContainer, define.OneShotInitContainer)
 		}
 		cliVals.InitContainerType = initctr
diff --git a/cmd/podman/farm/create.go b/cmd/podman/farm/create.go
index b9986b8118..8f10e2bb63 100644
--- a/cmd/podman/farm/create.go
+++ b/cmd/podman/farm/create.go
@@ -6,8 +6,8 @@ import (
 	"github.com/containers/common/pkg/completion"
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/podman/v4/cmd/podman/registry"
-	"github.com/containers/podman/v4/pkg/util"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -55,7 +55,7 @@ func create(cmd *cobra.Command, args []string) error {
 
 	for _, c := range connections {
 		if _, ok := cfg.Engine.ServiceDestinations[c]; ok {
-			if util.StringInSlice(c, cfg.Farms.List[farmName]) {
+			if slices.Contains(cfg.Farms.List[farmName], c) {
 				// Don't add duplicate connections to a farm
 				continue
 			}
diff --git a/cmd/podman/farm/update.go b/cmd/podman/farm/update.go
index 0bfa8081d8..55c6a8d998 100644
--- a/cmd/podman/farm/update.go
+++ b/cmd/podman/farm/update.go
@@ -8,8 +8,8 @@ import (
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/podman/v4/cmd/podman/common"
 	"github.com/containers/podman/v4/cmd/podman/registry"
-	"github.com/containers/podman/v4/pkg/util"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -91,7 +91,7 @@ func farmUpdate(cmd *cobra.Command, args []string) error {
 
 		for _, cRemove := range updateOpts.Remove {
 			connections := cfg.Farms.List[farmName]
-			if util.StringInSlice(cRemove, connections) {
+			if slices.Contains(connections, cRemove) {
 				delete(cMap, cRemove)
 			} else {
 				return fmt.Errorf("cannot remove from farm, %q is not a connection in the farm", cRemove)
diff --git a/cmd/podman/images/save.go b/cmd/podman/images/save.go
index 46376c2a14..1c6dbd5229 100644
--- a/cmd/podman/images/save.go
+++ b/cmd/podman/images/save.go
@@ -8,13 +8,13 @@ import (
 	"strings"
 
 	"github.com/containers/common/pkg/completion"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/cmd/podman/common"
 	"github.com/containers/podman/v4/cmd/podman/parse"
 	"github.com/containers/podman/v4/cmd/podman/registry"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/domain/entities"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 	"golang.org/x/term"
 )
 
@@ -38,7 +38,7 @@ var (
 			if err != nil {
 				return err
 			}
-			if !util.StringInSlice(format, common.ValidSaveFormats) {
+			if !slices.Contains(common.ValidSaveFormats, format) {
 				return fmt.Errorf("format value must be one of %s", strings.Join(common.ValidSaveFormats, " "))
 			}
 			return nil
diff --git a/cmd/podman/images/trust_set.go b/cmd/podman/images/trust_set.go
index 2ed91d9c46..cd88514fee 100644
--- a/cmd/podman/images/trust_set.go
+++ b/cmd/podman/images/trust_set.go
@@ -6,11 +6,11 @@ import (
 	"regexp"
 
 	"github.com/containers/common/pkg/completion"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/cmd/podman/common"
 	"github.com/containers/podman/v4/cmd/podman/registry"
 	"github.com/containers/podman/v4/pkg/domain/entities"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -60,7 +60,7 @@ func setTrust(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	if !util.StringInSlice(setOptions.Type, validTrustTypes) {
+	if !slices.Contains(validTrustTypes, setOptions.Type) {
 		return fmt.Errorf("invalid choice: %s (choose from 'accept', 'reject', 'signedBy', 'sigstoreSigned')", setOptions.Type)
 	}
 	return registry.ImageEngine().SetTrust(registry.Context(), args, setOptions)
diff --git a/cmd/podman/machine/rm.go b/cmd/podman/machine/rm.go
index d25922be11..ca1128e5d4 100644
--- a/cmd/podman/machine/rm.go
+++ b/cmd/podman/machine/rm.go
@@ -41,6 +41,9 @@ func init() {
 	formatFlagName := "force"
 	flags.BoolVarP(&destroyOptions.Force, formatFlagName, "f", false, "Stop and do not prompt before rming")
 
+	keysFlagName := "save-keys"
+	flags.BoolVar(&destroyOptions.SaveKeys, keysFlagName, false, "Do not delete SSH keys")
+
 	ignitionFlagName := "save-ignition"
 	flags.BoolVar(&destroyOptions.SaveIgnition, ignitionFlagName, false, "Do not delete ignition file")
 
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go
index 3c1a424537..ea6f822a9d 100644
--- a/cmd/podman/system/connection/list.go
+++ b/cmd/podman/system/connection/list.go
@@ -8,12 +8,12 @@ import (
 	"github.com/containers/common/pkg/completion"
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/common/pkg/report"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/cmd/podman/common"
 	"github.com/containers/podman/v4/cmd/podman/registry"
 	"github.com/containers/podman/v4/cmd/podman/system"
 	"github.com/containers/podman/v4/cmd/podman/validate"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -89,7 +89,7 @@ func inspect(cmd *cobra.Command, args []string) error {
 	}
 	rows := make([]namedDestination, 0)
 	for k, v := range cfg.Engine.ServiceDestinations {
-		if args != nil && !util.StringInSlice(k, args) {
+		if args != nil && !slices.Contains(args, k) {
 			continue
 		}
 
diff --git a/cmd/podman/system/connection/remove.go b/cmd/podman/system/connection/remove.go
index 72b24c10a8..1e6ac183fa 100644
--- a/cmd/podman/system/connection/remove.go
+++ b/cmd/podman/system/connection/remove.go
@@ -7,8 +7,8 @@ import (
 	"github.com/containers/podman/v4/cmd/podman/common"
 	"github.com/containers/podman/v4/cmd/podman/registry"
 	"github.com/containers/podman/v4/cmd/podman/system"
-	"github.com/containers/podman/v4/pkg/util"
 	"github.com/spf13/cobra"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -80,7 +80,7 @@ func rm(cmd *cobra.Command, args []string) error {
 
 	// If there are existing farm, remove the deleted connection that might be part of a farm
 	for k, v := range cfg.Farms.List {
-		index := util.IndexOfStringInSlice(args[0], v)
+		index := slices.Index(v, args[0])
 		if index > -1 {
 			cfg.Farms.List[k] = append(v[:index], v[index+1:]...)
 		}
diff --git a/docs/source/locale/ja/LC_MESSAGES/markdown.po b/docs/source/locale/ja/LC_MESSAGES/markdown.po
index daba666e6d..d625c9c3e5 100644
--- a/docs/source/locale/ja/LC_MESSAGES/markdown.po
+++ b/docs/source/locale/ja/LC_MESSAGES/markdown.po
@@ -18478,6 +18478,10 @@ msgstr ""
 msgid "Do not delete the VM image."
 msgstr ""
 
+#: ../../source/markdown/podman-machine-rm.1.md:43
+msgid "**--save-keys**"
+msgstr ""
+
 #: ../../source/markdown/podman-machine-rm.1.md:45
 msgid ""
 "Do not delete the SSH keys for the VM.  The system connection is always "
diff --git a/docs/source/markdown/podman-machine-rm.1.md b/docs/source/markdown/podman-machine-rm.1.md
index 9aa90c35ad..1224adbe1d 100644
--- a/docs/source/markdown/podman-machine-rm.1.md
+++ b/docs/source/markdown/podman-machine-rm.1.md
@@ -10,7 +10,7 @@ podman\-machine\-rm - Remove a virtual machine
 
 Remove a virtual machine and its related files.  What is actually deleted
 depends on the virtual machine type.  For all virtual machines, the generated
-podman system connections are deleted.  The ignition files
+SSH keys and the podman system connection are deleted.  The ignition files
 generated for that VM are also removed as is its image file on the filesystem.
 
 Users get a display of what is deleted and are required to confirm unless the option `--force`
@@ -39,6 +39,11 @@ Do not delete the generated ignition file.
 
 Do not delete the VM image.
 
+#### **--save-keys**
+
+Do not delete the SSH keys for the VM.  The system connection is always
+deleted.
+
 ## EXAMPLES
 
 Remove a VM named "test1":
@@ -48,6 +53,8 @@ $ podman machine rm test1
 
 The following files will be deleted:
 
+/home/user/.ssh/test1
+/home/user/.ssh/test1.pub
 /home/user/.config/containers/podman/machine/qemu/test1.ign
 /home/user/.local/share/containers/podman/machine/qemu/test1_fedora-coreos-33.20210315.1.0-qemu.x86_64.qcow2
 /home/user/.config/containers/podman/machine/qemu/test1.json
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 8e583de4c0..361a342f3f 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -47,6 +47,7 @@ import (
 	"github.com/opencontainers/runtime-tools/generate"
 	"github.com/opencontainers/selinux/go-selinux/label"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 	"golang.org/x/sys/unix"
 )
 
@@ -1794,7 +1795,7 @@ func (c *Container) mountNamedVolume(v *ContainerNamedVolume, mountpoint string)
 		return nil, err
 	}
 	_, hasNoCopy := vol.config.Options["nocopy"]
-	if vol.state.NeedsCopyUp && !cutil.StringInSlice("nocopy", v.Options) && !hasNoCopy {
+	if vol.state.NeedsCopyUp && !slices.Contains(v.Options, "nocopy") && !hasNoCopy {
 		logrus.Debugf("Copying up contents from container %s to volume %s", c.ID(), vol.Name())
 
 		srcDir, err := securejoin.SecureJoin(mountpoint, v.Dest)
diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go
index 75660f7cbe..3d91f653bd 100644
--- a/libpod/container_internal_common.go
+++ b/libpod/container_internal_common.go
@@ -32,7 +32,6 @@ import (
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/common/pkg/subscriptions"
 	"github.com/containers/common/pkg/umask"
-	cutil "github.com/containers/common/pkg/util"
 	is "github.com/containers/image/v5/storage"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/libpod/events"
@@ -54,6 +53,7 @@ import (
 	"github.com/opencontainers/selinux/go-selinux"
 	"github.com/opencontainers/selinux/go-selinux/label"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 	"golang.org/x/sys/unix"
 	cdi "tags.cncf.io/container-device-interface/pkg/cdi"
 )
@@ -193,7 +193,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
 	overrides := c.getUserOverrides()
 	execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, c.config.User, overrides)
 	if err != nil {
-		if cutil.StringInSlice(c.config.User, c.config.HostUsers) {
+		if slices.Contains(c.config.HostUsers, c.config.User) {
 			execUser, err = lookupHostUser(c.config.User)
 		}
 		if err != nil {
@@ -2495,7 +2495,7 @@ func (c *Container) setHomeEnvIfNeeded() error {
 		overrides := c.getUserOverrides()
 		execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, c.config.User, overrides)
 		if err != nil {
-			if cutil.StringInSlice(c.config.User, c.config.HostUsers) {
+			if slices.Contains(c.config.HostUsers, c.config.User) {
 				execUser, err = lookupHostUser(c.config.User)
 			}
 
diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go
index d8591e98e2..7807eeff23 100644
--- a/libpod/container_top_linux.go
+++ b/libpod/container_top_linux.go
@@ -16,13 +16,13 @@ import (
 	"syscall"
 	"unsafe"
 
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/rootless"
 	"github.com/containers/psgo"
 	"github.com/containers/storage/pkg/reexec"
 	"github.com/google/shlex"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 	"golang.org/x/sys/unix"
 )
 
@@ -231,7 +231,7 @@ func (c *Container) Top(descriptors []string) ([]string, error) {
 	// Only use ps(1) from the host when we know the container was not started with CAP_SYS_PTRACE,
 	// with it the container can access /proc/$pid/ files and potentially escape the container fs.
 	if c.config.Spec.Process.Capabilities != nil &&
-		!util.StringInSlice("CAP_SYS_PTRACE", c.config.Spec.Process.Capabilities.Effective) {
+		!slices.Contains(c.config.Spec.Process.Capabilities.Effective, "CAP_SYS_PTRACE") {
 		var retry bool
 		output, retry, err = c.execPS(psDescriptors)
 		if err != nil {
diff --git a/libpod/kube.go b/libpod/kube.go
index 104b9f1d5a..12895e4c30 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -17,7 +17,6 @@ import (
 
 	"github.com/containers/common/libnetwork/types"
 	"github.com/containers/common/pkg/config"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/annotations"
 	"github.com/containers/podman/v4/pkg/domain/entities"
@@ -32,6 +31,7 @@ import (
 	"github.com/containers/podman/v4/pkg/util"
 	"github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 )
 
 // GenerateForKube takes a slice of libpod containers and generates
@@ -729,7 +729,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic
 			for _, ulimit := range ctr.config.Spec.Process.Rlimits {
 				finalUlimit := strings.ToLower(strings.ReplaceAll(ulimit.Type, "RLIMIT_", "")) + "=" + strconv.Itoa(int(ulimit.Soft)) + ":" + strconv.Itoa(int(ulimit.Hard))
 				// compare ulimit with default list so we don't add it twice
-				if cutil.StringInSlice(finalUlimit, defaultUlimits) {
+				if slices.Contains(defaultUlimits, finalUlimit) {
 					continue
 				}
 
@@ -768,7 +768,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic
 					podDNS.Nameservers = make([]string, 0)
 				}
 				for _, s := range servers {
-					if !cutil.StringInSlice(s, podDNS.Nameservers) { // only append if it does not exist
+					if !slices.Contains(podDNS.Nameservers, s) { // only append if it does not exist
 						podDNS.Nameservers = append(podDNS.Nameservers, s)
 					}
 				}
@@ -779,7 +779,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic
 					podDNS.Searches = make([]string, 0)
 				}
 				for _, d := range domains {
-					if !cutil.StringInSlice(d, podDNS.Searches) { // only append if it does not exist
+					if !slices.Contains(podDNS.Searches, d) { // only append if it does not exist
 						podDNS.Searches = append(podDNS.Searches, d)
 					}
 				}
@@ -796,7 +796,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic
 	podName := removeUnderscores(ctrs[0].Name())
 	// Check if the pod name and container name will end up conflicting
 	// Append -pod if so
-	if cutil.StringInSlice(podName, ctrNames) {
+	if slices.Contains(ctrNames, podName) {
 		podName += "-pod"
 	}
 
@@ -1114,7 +1114,7 @@ func libpodMountsToKubeVolumeMounts(c *Container) ([]v1.VolumeMount, []v1.Volume
 
 // generateKubePersistentVolumeClaim converts a ContainerNamedVolume to a Kubernetes PersistentVolumeClaim
 func generateKubePersistentVolumeClaim(v *ContainerNamedVolume) (v1.VolumeMount, v1.Volume) {
-	ro := cutil.StringInSlice("ro", v.Options)
+	ro := slices.Contains(v.Options, "ro")
 
 	// To avoid naming conflicts with any host path mounts, add a unique suffix to the volume's name.
 	name := v.Name + "-pvc"
@@ -1175,7 +1175,7 @@ func generateKubeVolumeMount(m specs.Mount) (v1.VolumeMount, v1.Volume, error) {
 	}
 	vm.Name = name
 	vm.MountPath = m.Destination
-	if cutil.StringInSlice("ro", m.Options) {
+	if slices.Contains(m.Options, "ro") {
 		vm.ReadOnly = true
 	}
 
@@ -1216,7 +1216,7 @@ func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v
 	// Find caps in the defaultCaps but not in the container's
 	// those indicate a dropped cap
 	for _, capability := range defaultCaps {
-		if !cutil.StringInSlice(capability, containerCaps) {
+		if !slices.Contains(containerCaps, capability) {
 			if _, ok := dedupDrop[capability]; !ok {
 				drop = append(drop, v1.Capability(capability))
 				dedupDrop[capability] = true
@@ -1226,7 +1226,7 @@ func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v
 	// Find caps in the container but not in the defaults; those indicate
 	// an added cap
 	for _, capability := range containerCaps {
-		if !cutil.StringInSlice(capability, defaultCaps) {
+		if !slices.Contains(defaultCaps, capability) {
 			if _, ok := dedupAdd[capability]; !ok {
 				add = append(add, v1.Capability(capability))
 				dedupAdd[capability] = true
diff --git a/libpod/networking_common.go b/libpod/networking_common.go
index 3cf235b043..dc188b3fa4 100644
--- a/libpod/networking_common.go
+++ b/libpod/networking_common.go
@@ -12,13 +12,13 @@ import (
 	"github.com/containers/common/libnetwork/types"
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/common/pkg/machine"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/libpod/events"
 	"github.com/containers/podman/v4/pkg/namespaces"
 	"github.com/containers/podman/v4/pkg/rootless"
 	"github.com/containers/storage/pkg/lockfile"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 )
 
 // convertPortMappings will remove the HostIP part from the ports when running inside podman machine.
@@ -597,7 +597,7 @@ func getFreeInterfaceName(networks map[string]types.PerNetworkOptions) string {
 	}
 	for i := 0; i < 100000; i++ {
 		ifName := fmt.Sprintf("eth%d", i)
-		if !util.StringInSlice(ifName, ifNames) {
+		if !slices.Contains(ifNames, ifName) {
 			return ifName
 		}
 	}
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 944191accd..481d1b7c94 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -17,7 +17,6 @@ import (
 	"github.com/containers/common/libnetwork/types"
 	"github.com/containers/common/pkg/cgroups"
 	"github.com/containers/common/pkg/config"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/libpod/events"
 	"github.com/containers/podman/v4/libpod/shutdown"
@@ -31,6 +30,7 @@ import (
 	spec "github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/opencontainers/runtime-tools/generate"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 )
 
 // Contains the public Runtime API for containers
@@ -256,7 +256,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
 		for _, opts := range ctr.config.Networks {
 			if opts.InterfaceName != "" {
 				// check that no name is assigned to more than network
-				if cutil.StringInSlice(opts.InterfaceName, usedIfNames) {
+				if slices.Contains(usedIfNames, opts.InterfaceName) {
 					return nil, fmt.Errorf("network interface name %q is already assigned to another network", opts.InterfaceName)
 				}
 				usedIfNames = append(usedIfNames, opts.InterfaceName)
@@ -272,7 +272,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
 			if opts.InterfaceName == "" {
 				for i < 100000 {
 					ifName := fmt.Sprintf("eth%d", i)
-					if !cutil.StringInSlice(ifName, usedIfNames) {
+					if !slices.Contains(usedIfNames, ifName) {
 						opts.InterfaceName = ifName
 						usedIfNames = append(usedIfNames, ifName)
 						break
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go
index 2b335fecce..3dfbec004c 100644
--- a/libpod/runtime_pod.go
+++ b/libpod/runtime_pod.go
@@ -8,8 +8,8 @@ import (
 	"fmt"
 	"time"
 
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
+	"golang.org/x/exp/slices"
 )
 
 // Contains the public Runtime API for pods
@@ -145,7 +145,7 @@ func (r *Runtime) GetRunningPods() ([]*Pod, error) {
 	}
 	// Assemble running pods
 	for _, c := range containers {
-		if !util.StringInSlice(c.PodID(), pods) {
+		if !slices.Contains(pods, c.PodID()) {
 			pods = append(pods, c.PodID())
 			pod, err := r.GetPod(c.PodID())
 			if err != nil {
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 2fd97b717d..52ddc746d4 100644
--- a/pkg/domain/filters/containers.go
+++ b/pkg/domain/filters/containers.go
@@ -13,6 +13,7 @@ import (
 	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod"
 	"github.com/containers/podman/v4/libpod/define"
+	"golang.org/x/exp/slices"
 )
 
 // GenerateContainerFilterFuncs return ContainerFilter functions based of filter.
@@ -263,7 +264,7 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
 				return false
 			}
 			for _, net := range networks {
-				if util.StringInSlice(net, inputNetNames) {
+				if slices.Contains(inputNetNames, net) {
 					return true
 				}
 			}
diff --git a/pkg/domain/filters/pods.go b/pkg/domain/filters/pods.go
index 77de6cb430..9943ab7e57 100644
--- a/pkg/domain/filters/pods.go
+++ b/pkg/domain/filters/pods.go
@@ -12,6 +12,7 @@ import (
 	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod"
 	"github.com/containers/podman/v4/libpod/define"
+	"golang.org/x/exp/slices"
 )
 
 // GeneratePodFilterFunc takes a filter and filtervalue (key, value)
@@ -63,7 +64,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti
 		}, nil
 	case "ctr-status":
 		for _, filterValue := range filterValues {
-			if !util.StringInSlice(filterValue, []string{"created", "running", "paused", "stopped", "exited", "unknown"}) {
+			if !slices.Contains([]string{"created", "running", "paused", "stopped", "exited", "unknown"}, filterValue) {
 				return nil, fmt.Errorf("%s is not a valid status", filterValue)
 			}
 		}
@@ -100,7 +101,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti
 		}, nil
 	case "status":
 		for _, filterValue := range filterValues {
-			if !util.StringInSlice(filterValue, []string{"stopped", "running", "paused", "exited", "dead", "created", "degraded"}) {
+			if !slices.Contains([]string{"stopped", "running", "paused", "exited", "dead", "created", "degraded"}, filterValue) {
 				return nil, fmt.Errorf("%s is not a valid pod status", filterValue)
 			}
 		}
@@ -161,7 +162,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti
 				return false
 			}
 			for _, net := range networks {
-				if util.StringInSlice(net, inputNetNames) {
+				if slices.Contains(inputNetNames, net) {
 					return true
 				}
 			}
diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go
index d70fca268b..706c40a22f 100644
--- a/pkg/domain/infra/abi/images_list.go
+++ b/pkg/domain/infra/abi/images_list.go
@@ -7,7 +7,7 @@ import (
 	"github.com/containers/common/libimage"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/domain/entities"
-	"github.com/containers/podman/v4/pkg/util"
+	"golang.org/x/exp/slices"
 )
 
 func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
@@ -15,7 +15,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
 		Filters:     opts.Filter,
 		SetListData: true,
 	}
-	if !opts.All && !util.StringInSlice("intermediate=true", listImagesOptions.Filters) {
+	if !opts.All && !slices.Contains(listImagesOptions.Filters, "intermediate=true") {
 		// Filter intermediate images unless we want to list *all*.
 		// NOTE: it's a positive filter, so `intermediate=false` means
 		// to display non-intermediate images.
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go
index b51ba764bd..166176b4ea 100644
--- a/pkg/domain/infra/abi/network.go
+++ b/pkg/domain/infra/abi/network.go
@@ -8,9 +8,9 @@ import (
 
 	"github.com/containers/common/libnetwork/types"
 	netutil "github.com/containers/common/libnetwork/util"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/domain/entities"
+	"golang.org/x/exp/slices"
 )
 
 func (ic *ContainerEngine) NetworkUpdate(ctx context.Context, netName string, options entities.NetworkUpdateOptions) error {
@@ -121,7 +121,7 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
 			if err != nil {
 				return reports, err
 			}
-			if util.StringInSlice(name, networks) {
+			if slices.Contains(networks, name) {
 				// if user passes force, we nuke containers and pods
 				if !options.Force {
 					// Without the force option, we return an error
@@ -151,7 +151,7 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
 
 func (ic *ContainerEngine) NetworkCreate(ctx context.Context, network types.Network, createOptions *types.NetworkCreateOptions) (*types.Network, error) {
 	// TODO (5.0): Stop accepting "pasta" as value here
-	if util.StringInSlice(network.Name, []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns", "default"}) {
+	if slices.Contains([]string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns", "default"}, network.Name) {
 		return nil, fmt.Errorf("cannot create network with name %q because it conflicts with a valid network mode", network.Name)
 	}
 	network, err := ic.Libpod.Network().NetworkCreate(network, createOptions)
diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go
index 91feb8e29a..280ada1e84 100644
--- a/pkg/machine/applehv/machine.go
+++ b/pkg/machine/applehv/machine.go
@@ -22,9 +22,9 @@ import (
 	"github.com/containers/podman/v4/pkg/machine"
 	"github.com/containers/podman/v4/pkg/machine/applehv/vfkit"
 	"github.com/containers/podman/v4/pkg/machine/define"
-	"github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/machine/sockets"
 	"github.com/containers/podman/v4/pkg/machine/vmconfigs"
+    "github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/strongunits"
 	"github.com/containers/podman/v4/pkg/systemd/parser"
 	"github.com/containers/podman/v4/pkg/util"
@@ -202,7 +202,7 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
 		return false, err
 	}
 
-	m.IdentityPath = util.GetIdentityPath(define.DefaultIdentityName)
+	m.IdentityPath = util.GetIdentityPath(m.Name)
 	m.Rootful = opts.Rootful
 	m.RemoteUsername = opts.Username
 
@@ -241,10 +241,11 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
 	}
 
 	if len(opts.IgnitionPath) < 1 {
-		key, err = machine.GetSSHKeys(m.IdentityPath)
+		key, err = machine.CreateSSHKeys(m.IdentityPath)
 		if err != nil {
 			return false, err
 		}
+		callbackFuncs.Add(m.removeSSHKeys)
 	}
 
 	builder := ignition.NewIgnitionBuilder(ignition.DynamicIgnition{
@@ -259,8 +260,7 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
 	})
 
 	if len(opts.IgnitionPath) > 0 {
-		err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
-		return false, err
+		return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
 	}
 
 	if err := builder.GenerateIgnitionConfig(); err != nil {
@@ -293,6 +293,13 @@ func createReadyUnitFile() (string, error) {
 	return readyUnit.ToString()
 }
 
+func (m *MacMachine) removeSSHKeys() error {
+	if err := os.Remove(fmt.Sprintf("%s.pub", m.IdentityPath)); err != nil {
+		logrus.Error(err)
+	}
+	return os.Remove(m.IdentityPath)
+}
+
 func (m *MacMachine) removeSystemConnections() error {
 	return machine.RemoveConnections(m.Name, fmt.Sprintf("%s-root", m.Name))
 }
@@ -337,6 +344,9 @@ func (m *MacMachine) Inspect() (*machine.InspectInfo, error) {
 // collectFilesToDestroy retrieves the files that will be destroyed by `Remove`
 func (m *MacMachine) collectFilesToDestroy(opts machine.RemoveOptions) []string {
 	files := []string{}
+	if !opts.SaveKeys {
+		files = append(files, m.IdentityPath, m.IdentityPath+".pub")
+	}
 	if !opts.SaveIgnition {
 		files = append(files, m.IgnitionFile.GetPath())
 	}
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 9698e20d7c..57491ab94f 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -113,6 +113,7 @@ type StopOptions struct{}
 
 type RemoveOptions struct {
 	Force        bool
+	SaveKeys     bool
 	SaveImage    bool
 	SaveIgnition bool
 }
diff --git a/pkg/machine/define/config.go b/pkg/machine/define/config.go
index f7a8bbd48d..ba98908be1 100644
--- a/pkg/machine/define/config.go
+++ b/pkg/machine/define/config.go
@@ -1,4 +1,3 @@
 package define
 
 const UserCertsTargetPath = "/etc/containers/certs.d"
-const DefaultIdentityName = "machine"
diff --git a/pkg/machine/hyperv/machine.go b/pkg/machine/hyperv/machine.go
index ea8d522144..8ff0791358 100644
--- a/pkg/machine/hyperv/machine.go
+++ b/pkg/machine/hyperv/machine.go
@@ -21,8 +21,8 @@ import (
 	"github.com/containers/podman/v4/pkg/machine"
 	"github.com/containers/podman/v4/pkg/machine/define"
 	"github.com/containers/podman/v4/pkg/machine/hyperv/vsock"
-	"github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/machine/vmconfigs"
+	"github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/strongunits"
 	"github.com/containers/podman/v4/pkg/systemd/parser"
 	"github.com/containers/podman/v4/pkg/util"
@@ -178,7 +178,7 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
 		return nil
 	})
 
-	m.IdentityPath = util.GetIdentityPath(define.DefaultIdentityName)
+	m.IdentityPath = util.GetIdentityPath(m.Name)
 
 	if m.UID == 0 {
 		m.UID = 1000
@@ -205,10 +205,11 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
 	callbackFuncs.Add(m.removeSystemConnections)
 
 	if len(opts.IgnitionPath) < 1 {
-		key, err = machine.GetSSHKeys(m.IdentityPath)
+		key, err = machine.CreateSSHKeys(m.IdentityPath)
 		if err != nil {
 			return false, err
 		}
+		callbackFuncs.Add(m.removeSSHKeys)
 	}
 
 	m.ResourceConfig = vmconfigs.ResourceConfig{
@@ -232,8 +233,7 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
 	// If the user provides an ignition file, we need to
 	// copy it into the conf dir
 	if len(opts.IgnitionPath) > 0 {
-		err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
-		return false, err
+		return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
 	}
 	callbackFuncs.Add(m.IgnitionFile.Delete)
 
@@ -319,6 +319,13 @@ func (m *HyperVMachine) unregisterMachine() error {
 	return vm.Remove("")
 }
 
+func (m *HyperVMachine) removeSSHKeys() error {
+	if err := os.Remove(fmt.Sprintf("%s.pub", m.IdentityPath)); err != nil {
+		logrus.Error(err)
+	}
+	return os.Remove(m.IdentityPath)
+}
+
 func (m *HyperVMachine) removeSystemConnections() error {
 	return machine.RemoveConnections(m.Name, fmt.Sprintf("%s-root", m.Name))
 }
@@ -371,6 +378,10 @@ func (m *HyperVMachine) Inspect() (*machine.InspectInfo, error) {
 // collectFilesToDestroy retrieves the files that will be destroyed by `Remove`
 func (m *HyperVMachine) collectFilesToDestroy(opts machine.RemoveOptions, diskPath *string) []string {
 	files := []string{}
+
+	if !opts.SaveKeys {
+		files = append(files, m.IdentityPath, m.IdentityPath+".pub")
+	}
 	if !opts.SaveIgnition {
 		files = append(files, m.IgnitionFile.GetPath())
 	}
diff --git a/pkg/machine/keys.go b/pkg/machine/keys.go
index e151aa1174..d46f759f71 100644
--- a/pkg/machine/keys.go
+++ b/pkg/machine/keys.go
@@ -36,20 +36,6 @@ func CreateSSHKeys(writeLocation string) (string, error) {
 	return strings.TrimSuffix(string(b), "\n"), nil
 }
 
-// GetSSHKeys checks to see if there is a ssh key at the provided location.
-// If not, we create the priv and pub keys. The ssh key is then returned.
-func GetSSHKeys(identityPath string) (string, error) {
-	if _, err := os.Stat(identityPath); err == nil {
-		b, err := os.ReadFile(identityPath + ".pub")
-		if err != nil {
-			return "", err
-		}
-		return strings.TrimSuffix(string(b), "\n"), nil
-	}
-
-	return CreateSSHKeys(identityPath)
-}
-
 func CreateSSHKeysPrefix(identityPath string, passThru bool, skipExisting bool, prefix ...string) (string, error) {
 	_, e := os.Stat(identityPath)
 	if !skipExisting || errors.Is(e, os.ErrNotExist) {
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 14ab01d790..0845626ae6 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -124,7 +124,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
 	defer callbackFuncs.CleanIfErr(&err)
 	go callbackFuncs.CleanOnSignal()
 
-	v.IdentityPath = util.GetIdentityPath(define.DefaultIdentityName)
+	v.IdentityPath = util.GetIdentityPath(v.Name)
 	v.Rootful = opts.Rootful
 
 	imagePath, strm, err := machine.Pull(opts.ImagePath, opts.Name, VirtualizationProvider())
@@ -169,10 +169,11 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
 	// User has provided ignition file so keygen
 	// will be skipped.
 	if len(opts.IgnitionPath) < 1 {
-		key, err = machine.GetSSHKeys(v.IdentityPath)
+		key, err = machine.CreateSSHKeys(v.IdentityPath)
 		if err != nil {
 			return false, err
 		}
+		callbackFuncs.Add(v.removeSSHKeys)
 	}
 	// Run arch specific things that need to be done
 	if err = v.prepare(); err != nil {
@@ -205,8 +206,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
 	// If the user provides an ignition file, we need to
 	// copy it into the conf dir
 	if len(opts.IgnitionPath) > 0 {
-		err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
-		return false, err
+		return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
 	}
 
 	if err := builder.GenerateIgnitionConfig(); err != nil {
@@ -238,6 +238,13 @@ func createReadyUnitFile() (string, error) {
 	return readyUnit.ToString()
 }
 
+func (v *MachineVM) removeSSHKeys() error {
+	if err := os.Remove(fmt.Sprintf("%s.pub", v.IdentityPath)); err != nil {
+		logrus.Error(err)
+	}
+	return os.Remove(v.IdentityPath)
+}
+
 func (v *MachineVM) removeSystemConnections() error {
 	return machine.RemoveConnections(v.Name, fmt.Sprintf("%s-root", v.Name))
 }
@@ -916,6 +923,9 @@ func NewQMPMonitor(network, name string, timeout time.Duration) (command.Monitor
 func (v *MachineVM) collectFilesToDestroy(opts machine.RemoveOptions) ([]string, error) {
 	files := []string{}
 	// Collect all the files that need to be destroyed
+	if !opts.SaveKeys {
+		files = append(files, v.IdentityPath, v.IdentityPath+".pub")
+	}
 	if !opts.SaveIgnition {
 		files = append(files, v.getIgnitionFile())
 	}
@@ -958,7 +968,7 @@ func (v *MachineVM) removeQMPMonitorSocketAndVMPidFile() {
 	}
 }
 
-// Remove deletes all the files associated with a machine including the image itself
+// Remove deletes all the files associated with a machine including ssh keys, the image itself
 func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func() error, error) {
 	var (
 		files []string
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go
index ee0301070e..efb5485239 100644
--- a/pkg/machine/wsl/machine.go
+++ b/pkg/machine/wsl/machine.go
@@ -19,8 +19,8 @@ import (
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/podman/v4/pkg/machine"
 	"github.com/containers/podman/v4/pkg/machine/define"
-	"github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/machine/vmconfigs"
+	"github.com/containers/podman/v4/pkg/machine/ignition"
 	"github.com/containers/podman/v4/pkg/machine/wsl/wutil"
 	"github.com/containers/podman/v4/pkg/util"
 	"github.com/containers/podman/v4/utils"
@@ -411,7 +411,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
 	}
 
 	_ = setupWslProxyEnv()
-	v.IdentityPath = util.GetIdentityPath(define.DefaultIdentityName)
+	v.IdentityPath = util.GetIdentityPath(v.Name)
 	v.Rootful = opts.Rootful
 	v.Version = currentMachineVersion
 
@@ -452,6 +452,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
 	if err = createKeys(v, dist); err != nil {
 		return false, err
 	}
+	callbackFuncs.Add(v.removeSSHKeys)
 
 	// Cycle so that user change goes into effect
 	_ = terminateDist(dist)
@@ -493,6 +494,13 @@ func (v *MachineVM) removeMachineImage() error {
 	return utils.GuardedRemoveAll(v.ImagePath)
 }
 
+func (v *MachineVM) removeSSHKeys() error {
+	if err := utils.GuardedRemoveAll(fmt.Sprintf("%s.pub", v.IdentityPath)); err != nil {
+		logrus.Error(err)
+	}
+	return utils.GuardedRemoveAll(v.IdentityPath)
+}
+
 func (v *MachineVM) removeSystemConnections() error {
 	return machine.RemoveConnections(v.Name, fmt.Sprintf("%s-root", v.Name))
 }
@@ -1049,7 +1057,7 @@ func wslPipe(input string, dist string, arg ...string) error {
 }
 
 func wslCreateKeys(identityPath string, dist string) (string, error) {
-	return machine.CreateSSHKeysPrefix(identityPath, true, true, "wsl", "-u", "root", "-d", dist)
+	return machine.CreateSSHKeysPrefix(identityPath, true, false, "wsl", "-u", "root", "-d", dist)
 }
 
 func runCmdPassThrough(name string, arg ...string) error {
@@ -1597,6 +1605,9 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
 	defer v.lock.Unlock()
 
 	// Collect all the files that need to be destroyed
+	if !opts.SaveKeys {
+		files = append(files, v.IdentityPath, v.IdentityPath+".pub")
+	}
 	if !opts.SaveImage {
 		files = append(files, v.ImagePath)
 	}
diff --git a/pkg/specgen/container_validate.go b/pkg/specgen/container_validate.go
index c6a8baddd7..2371434656 100644
--- a/pkg/specgen/container_validate.go
+++ b/pkg/specgen/container_validate.go
@@ -5,8 +5,8 @@ import (
 	"fmt"
 	"strings"
 
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
+	"golang.org/x/exp/slices"
 )
 
 var (
@@ -59,7 +59,7 @@ func (s *SpecGenerator) Validate() error {
 		return fmt.Errorf("cannot set hostname when running in the host UTS namespace: %w", ErrInvalidSpecConfig)
 	}
 	// systemd values must be true, false, or always
-	if len(s.ContainerBasicConfig.Systemd) > 0 && !util.StringInSlice(strings.ToLower(s.ContainerBasicConfig.Systemd), SystemDValues) {
+	if len(s.ContainerBasicConfig.Systemd) > 0 && !slices.Contains(SystemDValues, strings.ToLower(s.ContainerBasicConfig.Systemd)) {
 		return fmt.Errorf("--systemd values must be one of %q: %w", strings.Join(SystemDValues, ", "), ErrInvalidSpecConfig)
 	}
 
@@ -75,7 +75,7 @@ func (s *SpecGenerator) Validate() error {
 		return exclusiveOptions("rootfs", "image")
 	}
 	// imagevolumemode must be one of ignore, tmpfs, or anonymous if given
-	if len(s.ContainerStorageConfig.ImageVolumeMode) > 0 && !util.StringInSlice(strings.ToLower(s.ContainerStorageConfig.ImageVolumeMode), ImageVolumeModeValues) {
+	if len(s.ContainerStorageConfig.ImageVolumeMode) > 0 && !slices.Contains(ImageVolumeModeValues, strings.ToLower(s.ContainerStorageConfig.ImageVolumeMode)) {
 		return fmt.Errorf("invalid ImageVolumeMode %q, value must be one of %s",
 			s.ContainerStorageConfig.ImageVolumeMode, strings.Join(ImageVolumeModeValues, ","))
 	}
diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go
index bae88407f3..930f1497f0 100644
--- a/pkg/specgen/generate/kube/kube.go
+++ b/pkg/specgen/generate/kube/kube.go
@@ -21,7 +21,6 @@ import (
 	"github.com/containers/common/pkg/config"
 	"github.com/containers/common/pkg/parse"
 	"github.com/containers/common/pkg/secrets"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/image/v5/manifest"
 	itypes "github.com/containers/image/v5/types"
 	"github.com/containers/podman/v4/libpod/define"
@@ -487,7 +486,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
 				// Make sure the z/Z option is not already there (from editing the YAML)
 				if k == define.BindMountPrefix {
 					lastIndex := strings.LastIndex(v, ":")
-					if lastIndex != -1 && v[:lastIndex] == volumeSource.Source && !cutil.StringInSlice("z", options) && !cutil.StringInSlice("Z", options) {
+					if lastIndex != -1 && v[:lastIndex] == volumeSource.Source && !slices.Contains(options, "z") && !slices.Contains(options, "Z") {
 						options = append(options, v[lastIndex+1:])
 					}
 				}
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go
index 1d0d9c2059..3284d9181e 100644
--- a/pkg/specgen/generate/ports.go
+++ b/pkg/specgen/generate/ports.go
@@ -10,12 +10,11 @@ import (
 
 	"github.com/containers/common/libimage"
 	"github.com/containers/common/libnetwork/types"
-	"github.com/containers/podman/v4/utils"
-
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/pkg/specgen"
 	"github.com/containers/podman/v4/pkg/specgenutil"
+	"github.com/containers/podman/v4/utils"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 )
 
 const (
@@ -332,7 +331,7 @@ func ParsePortMapping(portMappings []types.PortMapping, exposePorts map[uint16][
 
 func appendProtocolsNoDuplicates(slice []string, protocols []string) []string {
 	for _, proto := range protocols {
-		if util.StringInSlice(proto, slice) {
+		if slices.Contains(slice, proto) {
 			continue
 		}
 		slice = append(slice, proto)
diff --git a/pkg/specgen/generate/security_linux.go b/pkg/specgen/generate/security_linux.go
index 92a2362870..ff288285f1 100644
--- a/pkg/specgen/generate/security_linux.go
+++ b/pkg/specgen/generate/security_linux.go
@@ -10,7 +10,6 @@ import (
 	"github.com/containers/common/pkg/apparmor"
 	"github.com/containers/common/pkg/capabilities"
 	"github.com/containers/common/pkg/config"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/specgen"
@@ -18,6 +17,7 @@ import (
 	"github.com/opencontainers/runtime-tools/generate"
 	"github.com/opencontainers/selinux/go-selinux/label"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 )
 
 // setLabelOpts sets the label options of the SecurityConfig according to the
@@ -123,7 +123,7 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
 		// capabilities, required to run the container.
 		var capsRequiredRequested []string
 		for key, val := range s.Labels {
-			if cutil.StringInSlice(key, capabilities.ContainerImageLabels) {
+			if slices.Contains(capabilities.ContainerImageLabels, key) {
 				capsRequiredRequested = strings.Split(val, ",")
 			}
 		}
@@ -137,7 +137,7 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
 			}
 			// Verify all capRequired are in the capList
 			for _, cap := range capsRequired {
-				if !cutil.StringInSlice(cap, caplist) {
+				if !slices.Contains(caplist, cap) {
 					privCapsRequired = append(privCapsRequired, cap)
 				}
 			}
diff --git a/pkg/specgen/namespaces.go b/pkg/specgen/namespaces.go
index 94c96794a3..04d4b08f43 100644
--- a/pkg/specgen/namespaces.go
+++ b/pkg/specgen/namespaces.go
@@ -9,7 +9,6 @@ import (
 
 	"github.com/containers/common/libnetwork/types"
 	"github.com/containers/common/pkg/cgroups"
-	cutil "github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/namespaces"
 	"github.com/containers/podman/v4/pkg/rootless"
@@ -17,6 +16,7 @@ import (
 	"github.com/containers/storage"
 	spec "github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/opencontainers/runtime-tools/generate"
+	"golang.org/x/exp/slices"
 )
 
 type NamespaceMode string
@@ -445,8 +445,8 @@ func ParseNetworkFlag(networks []string, pastaNetworkNameExists bool) (Namespace
 				return toReturn, nil, nil, fmt.Errorf("network name cannot be empty: %w", define.ErrInvalidArg)
 			}
 			// TODO (5.0): Don't accept string(Pasta) here once we drop pastaNetworkNameExists
-			if cutil.StringInSlice(parts[0], []string{string(Bridge), string(Slirp), string(FromPod), string(NoNetwork),
-				string(Default), string(Private), string(Path), string(FromContainer), string(Host)}) {
+			if slices.Contains([]string{string(Bridge), string(Slirp), string(FromPod), string(NoNetwork),
+				string(Default), string(Private), string(Path), string(FromContainer), string(Host)}, parts[0]) {
 				return toReturn, nil, nil, fmt.Errorf("can only set extra network names, selected mode %s conflicts with bridge: %w", parts[0], define.ErrInvalidArg)
 			}
 			netOpts := types.PerNetworkOptions{}
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index b3ccbb4c23..0b1abeea3b 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -18,7 +18,6 @@ import (
 
 	"github.com/BurntSushi/toml"
 	"github.com/containers/common/pkg/config"
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/image/v5/types"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/errorhandling"
@@ -161,11 +160,6 @@ func ParseRegistryCreds(creds string) (*types.DockerAuthConfig, error) {
 	}, nil
 }
 
-// StringInSlice is deprecated, use containers/common/pkg/util/StringInSlice
-func StringInSlice(s string, sl []string) bool {
-	return util.StringInSlice(s, sl)
-}
-
 // StringMatchRegexSlice determines if a given string matches one of the given regexes, returns bool
 func StringMatchRegexSlice(s string, re []string) bool {
 	for _, r := range re {
@@ -177,17 +171,6 @@ func StringMatchRegexSlice(s string, re []string) bool {
 	return false
 }
 
-// IndexOfStringInSlice returns the index if a string is in a slice, otherwise
-// it returns -1 if the string is not found
-func IndexOfStringInSlice(s string, sl []string) int {
-	for i := range sl {
-		if sl[i] == s {
-			return i
-		}
-	}
-	return -1
-}
-
 // ParseSignal parses and validates a signal name or number.
 func ParseSignal(rawSignal string) (syscall.Signal, error) {
 	// Strip off leading dash, to allow -1 or -HUP
@@ -1184,7 +1167,7 @@ func ExitCode(err error) int {
 }
 
 func GetIdentityPath(name string) string {
-	return filepath.Join(homedir.Get(), ".local", "share", "containers", "podman", "machine", name)
+	return filepath.Join(homedir.Get(), ".ssh", name)
 }
 
 func Tmpdir() string {


Test patch:
diff --git a/pkg/bindings/test/common_test.go b/pkg/bindings/test/common_test.go
index c499b66c05..acc9a62cf7 100644
--- a/pkg/bindings/test/common_test.go
+++ b/pkg/bindings/test/common_test.go
@@ -246,17 +246,6 @@ func (b *bindingTest) PodcreateAndExpose(name *string, port *string) {
 	b.runPodman(command).Wait(45)
 }
 
-// StringInSlice returns a boolean based on whether a given
-// string is in a given slice
-func StringInSlice(s string, sl []string) bool {
-	for _, val := range sl {
-		if s == val {
-			return true
-		}
-	}
-	return false
-}
-
 var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
 	// make cache dir
 	err := os.MkdirAll(ImageCacheDir, 0777)
diff --git a/pkg/bindings/test/networks_test.go b/pkg/bindings/test/networks_test.go
index d790db1a82..55db4e7a5b 100644
--- a/pkg/bindings/test/networks_test.go
+++ b/pkg/bindings/test/networks_test.go
@@ -13,6 +13,7 @@ import (
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	"github.com/onsi/gomega/gexec"
+	"golang.org/x/exp/slices"
 )
 
 var _ = Describe("Podman networks", func() {
@@ -148,7 +149,7 @@ var _ = Describe("Podman networks", func() {
 		Expect(len(list)).To(BeNumerically(">=", 5))
 		for _, n := range list {
 			if n.Name != "podman" {
-				Expect(StringInSlice(n.Name, netNames)).To(BeTrue())
+				Expect(slices.Contains(netNames, n.Name)).To(BeTrue())
 			}
 		}
 
diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go
index 8627877d1e..7e559714bd 100644
--- a/pkg/bindings/test/pods_test.go
+++ b/pkg/bindings/test/pods_test.go
@@ -16,6 +16,7 @@ import (
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	"github.com/onsi/gomega/gexec"
+	"golang.org/x/exp/slices"
 )
 
 var _ = Describe("Podman pods", func() {
@@ -85,8 +86,8 @@ var _ = Describe("Podman pods", func() {
 		for _, i := range podSummary {
 			names = append(names, i.Name)
 		}
-		Expect(StringInSlice(newpod, names)).To(BeTrue())
-		Expect(StringInSlice("newpod2", names)).To(BeTrue())
+		Expect(slices.Contains(names, newpod)).To(BeTrue())
+		Expect(slices.Contains(names, "newpod2")).To(BeTrue())
 	})
 
 	// The test validates the list pod endpoint with passing filters as the params.
@@ -130,7 +131,7 @@ var _ = Describe("Podman pods", func() {
 		for _, i := range filteredPods {
 			names = append(names, i.Name)
 		}
-		Expect(StringInSlice("newpod2", names)).To(BeTrue())
+		Expect(slices.Contains(names, "newpod2")).To(BeTrue())
 
 		// Validate list pod with id filter
 		filters = make(map[string][]string)
@@ -146,7 +147,7 @@ var _ = Describe("Podman pods", func() {
 		for _, i := range filteredPods {
 			names = append(names, i.Name)
 		}
-		Expect(StringInSlice("newpod", names)).To(BeTrue())
+		Expect(slices.Contains(names, "newpod")).To(BeTrue())
 
 		// Using multiple filters
 		filters["name"] = []string{newpod}
@@ -158,7 +159,7 @@ var _ = Describe("Podman pods", func() {
 		for _, i := range filteredPods {
 			names = append(names, i.Name)
 		}
-		Expect(StringInSlice("newpod", names)).To(BeTrue())
+		Expect(slices.Contains(names, "newpod")).To(BeTrue())
 	})
 
 	// The test validates if the exists responds
diff --git a/pkg/bindings/test/volumes_test.go b/pkg/bindings/test/volumes_test.go
index a54c56178f..62950d3fd0 100644
--- a/pkg/bindings/test/volumes_test.go
+++ b/pkg/bindings/test/volumes_test.go
@@ -14,6 +14,7 @@ import (
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	"github.com/onsi/gomega/gexec"
+	"golang.org/x/exp/slices"
 )
 
 var _ = Describe("Podman volumes", func() {
@@ -117,7 +118,7 @@ var _ = Describe("Podman volumes", func() {
 		Expect(err).ToNot(HaveOccurred())
 		Expect(vols).To(HaveLen(5))
 		for _, v := range vols {
-			Expect(StringInSlice(v.Name, volNames)).To(BeTrue())
+			Expect(slices.Contains(volNames, v.Name)).To(BeTrue())
 		}
 
 		// list with bad filter should be 500
diff --git a/pkg/machine/e2e/config_rm_test.go b/pkg/machine/e2e/config_rm_test.go
index c638e6ac05..f0cf15a06f 100644
--- a/pkg/machine/e2e/config_rm_test.go
+++ b/pkg/machine/e2e/config_rm_test.go
@@ -5,11 +5,13 @@ type rmMachine struct {
 	  -f, --force           Stop and do not prompt before rming
 	      --save-ignition   Do not delete ignition file
 	      --save-image      Do not delete the image file
+	      --save-keys       Do not delete SSH keys
 
 	*/
 	force        bool
 	saveIgnition bool
 	saveImage    bool
+	saveKeys     bool
 
 	cmd []string
 }
@@ -25,6 +27,9 @@ func (i *rmMachine) buildCmd(m *machineTestBuilder) []string {
 	if i.saveImage {
 		cmd = append(cmd, "--save-image")
 	}
+	if i.saveKeys {
+		cmd = append(cmd, "--save-keys")
+	}
 	cmd = append(cmd, m.name)
 	i.cmd = cmd
 	return cmd
@@ -44,3 +49,8 @@ func (i *rmMachine) withSaveImage() *rmMachine {
 	i.saveImage = true
 	return i
 }
+
+func (i *rmMachine) withSaveKeys() *rmMachine {
+	i.saveKeys = true
+	return i
+}
diff --git a/pkg/machine/e2e/config_test.go b/pkg/machine/e2e/config_test.go
index 18b961a0d5..354b3be742 100644
--- a/pkg/machine/e2e/config_test.go
+++ b/pkg/machine/e2e/config_test.go
@@ -12,13 +12,13 @@ import (
 
 	"github.com/containers/podman/v4/pkg/machine"
 	"github.com/containers/podman/v4/pkg/machine/define"
-	"github.com/containers/podman/v4/pkg/util"
 	"github.com/containers/storage/pkg/stringid"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	"github.com/onsi/gomega/format"
 	. "github.com/onsi/gomega/gexec"
 	"github.com/onsi/gomega/types"
+	"golang.org/x/exp/slices"
 )
 
 var originalHomeDir = os.Getenv("HOME")
@@ -122,7 +122,7 @@ func (m *machineTestBuilder) setName(name string) *machineTestBuilder {
 // representation of the podman machine command
 func (m *machineTestBuilder) setCmd(mc machineCommand) *machineTestBuilder {
 	// If no name for the machine exists, we set a random name.
-	if !util.StringInSlice(m.name, m.names) {
+	if !slices.Contains(m.names, m.name) {
 		if len(m.name) < 1 {
 			m.name = randomString()
 		}
diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go
index 27b0b3d060..84f064777b 100644
--- a/pkg/machine/e2e/init_test.go
+++ b/pkg/machine/e2e/init_test.go
@@ -303,7 +303,7 @@ var _ = Describe("podman machine init", func() {
 		img := inspectSession.outputToString()
 
 		rm := rmMachine{}
-		removeSession, err := mb.setCmd(rm.withForce()).run()
+		removeSession, err := mb.setCmd(rm.withForce().withSaveKeys()).run()
 		Expect(err).ToNot(HaveOccurred())
 		Expect(removeSession).To(Exit(0))
 
@@ -313,21 +313,20 @@ var _ = Describe("podman machine init", func() {
 		Expect(err).ToNot(HaveOccurred())
 		Expect(ec).To(Equal(125))
 
+		// Clashing keys - init fails
+		i = new(initMachine)
+		session, err = mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
+		Expect(err).ToNot(HaveOccurred())
+		Expect(session).To(Exit(125))
+
+		// ensure files created by init are cleaned up on init failure
+		_, err = os.Stat(img)
+		Expect(err).To(HaveOccurred())
+		_, err = os.Stat(cfgpth)
+		Expect(err).To(HaveOccurred())
+
 		// WSL does not use ignition
 		if testProvider.VMType() != define.WSLVirt {
-			// Bad ignition path - init fails
-			i = new(initMachine)
-			i.ignitionPath = "/bad/path"
-			session, err = mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
-			Expect(err).ToNot(HaveOccurred())
-			Expect(session).To(Exit(125))
-
-			// ensure files created by init are cleaned up on init failure
-			_, err = os.Stat(img)
-			Expect(err).To(HaveOccurred())
-			_, err = os.Stat(cfgpth)
-			Expect(err).To(HaveOccurred())
-
 			_, err = os.Stat(ign)
 			Expect(err).To(HaveOccurred())
 		}
diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go
index 4cdef055e9..2a8f51f13b 100644
--- a/pkg/machine/e2e/list_test.go
+++ b/pkg/machine/e2e/list_test.go
@@ -4,12 +4,12 @@ import (
 	"strings"
 	"time"
 
-	"github.com/containers/common/pkg/util"
 	"github.com/containers/podman/v4/pkg/domain/entities"
 	jsoniter "github.com/json-iterator/go"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	. "github.com/onsi/gomega/gexec"
+	"golang.org/x/exp/slices"
 )
 
 var _ = Describe("podman machine list", func() {
@@ -75,8 +75,8 @@ var _ = Describe("podman machine list", func() {
 
 		listNames := secondList.outputToStringSlice()
 		stripAsterisk(listNames)
-		Expect(util.StringInSlice(name1, listNames)).To(BeTrue())
-		Expect(util.StringInSlice(name2, listNames)).To(BeTrue())
+		Expect(slices.Contains(listNames, name1)).To(BeTrue())
+		Expect(slices.Contains(listNames, name2)).To(BeTrue())
 	})
 
 	It("list machine: check if running while starting", func() {
@@ -136,7 +136,7 @@ var _ = Describe("podman machine list", func() {
 
 		listNames := listSession.outputToStringSlice()
 		stripAsterisk(listNames)
-		Expect(util.StringInSlice(name1, listNames)).To(BeTrue())
+		Expect(slices.Contains(listNames, name1)).To(BeTrue())
 
 		// --format json
 		list2 := new(listMachine)
diff --git a/pkg/machine/e2e/rm_test.go b/pkg/machine/e2e/rm_test.go
index 11f76de25b..a3a1ab6ef0 100644
--- a/pkg/machine/e2e/rm_test.go
+++ b/pkg/machine/e2e/rm_test.go
@@ -3,7 +3,6 @@ package e2e_test
 import (
 	"fmt"
 	"os"
-	"path/filepath"
 
 	"github.com/containers/podman/v4/pkg/machine/define"
 	. "github.com/onsi/ginkgo/v2"
@@ -81,7 +80,7 @@ var _ = Describe("podman machine rm", func() {
 		Expect(ec).To(Equal(125))
 	})
 
-	It("machine rm --save-ignition --save-image", func() {
+	It("machine rm --save-keys, --save-ignition, --save-image", func() {
 		i := new(initMachine)
 		session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
 		Expect(err).ToNot(HaveOccurred())
@@ -105,7 +104,7 @@ var _ = Describe("podman machine rm", func() {
 		img := inspectSession.outputToString()
 
 		rm := rmMachine{}
-		removeSession, err := mb.setCmd(rm.withForce().withSaveIgnition().withSaveImage()).run()
+		removeSession, err := mb.setCmd(rm.withForce().withSaveIgnition().withSaveImage().withSaveKeys()).run()
 		Expect(err).ToNot(HaveOccurred())
 		Expect(removeSession).To(Exit(0))
 
@@ -128,71 +127,4 @@ var _ = Describe("podman machine rm", func() {
 		_, err = os.Stat(img)
 		Expect(err).ToNot(HaveOccurred())
 	})
-
-	It("Remove machine sharing ssh key with another machine", func() {
-		expectedIdentityPathSuffix := filepath.Join(".local", "share", "containers", "podman", "machine", define.DefaultIdentityName)
-
-		fooName := "foo"
-		foo := new(initMachine)
-		session, err := mb.setName(fooName).setCmd(foo.withImagePath(mb.imagePath)).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(session).To(Exit(0))
-
-		barName := "bar"
-		bar := new(initMachine)
-		session, err = mb.setName(barName).setCmd(bar.withImagePath(mb.imagePath).withNow()).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(session).To(Exit(0))
-
-		inspectFoo := new(inspectMachine)
-		inspectFoo = inspectFoo.withFormat("{{.SSHConfig.IdentityPath}}")
-		inspectSession, err := mb.setName(fooName).setCmd(inspectFoo).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(inspectSession).To(Exit(0))
-		Expect(inspectSession.outputToString()).To(ContainSubstring(expectedIdentityPathSuffix))
-		fooIdentityPath := inspectSession.outputToString()
-
-		inspectBar := new(inspectMachine)
-		inspectBar = inspectBar.withFormat("{{.SSHConfig.IdentityPath}}")
-		inspectSession, err = mb.setName(barName).setCmd(inspectBar).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(inspectSession).To(Exit(0))
-		Expect(inspectSession.outputToString()).To(Equal(fooIdentityPath))
-
-		rmFoo := new(rmMachine)
-		stop, err := mb.setName(fooName).setCmd(rmFoo.withForce()).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(stop).To(Exit(0))
-
-		// removal of foo should not affect the ability to ssh into the bar machine
-		sshBar := new(sshMachine)
-		sshSession, err := mb.setName(barName).setCmd(sshBar.withSSHCommand([]string{"echo", "foo"})).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(sshSession).To(Exit(0))
-	})
-
-	It("Removing all machines doesn't delete ssh keys", func() {
-		fooName := "foo"
-		foo := new(initMachine)
-		session, err := mb.setName(fooName).setCmd(foo.withImagePath(mb.imagePath)).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(session).To(Exit(0))
-
-		inspectFoo := new(inspectMachine)
-		inspectFoo = inspectFoo.withFormat("{{.SSHConfig.IdentityPath}}")
-		inspectSession, err := mb.setName(fooName).setCmd(inspectFoo).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(inspectSession).To(Exit(0))
-		fooIdentityPath := inspectSession.outputToString()
-
-		rmFoo := new(rmMachine)
-		stop, err := mb.setName(fooName).setCmd(rmFoo.withForce()).run()
-		Expect(err).ToNot(HaveOccurred())
-		Expect(stop).To(Exit(0))
-
-		_, err = os.Stat(fooIdentityPath)
-		Expect(err).ToNot(HaveOccurred())
-		_, err = os.Stat(fooIdentityPath + ".pub")
-		Expect(err).ToNot(HaveOccurred())
-	})
 })
diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go
index 38a65f453f..3d01be5dd8 100644
--- a/pkg/util/utils_test.go
+++ b/pkg/util/utils_test.go
@@ -13,10 +13,6 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
-var (
-	sliceData = []string{"one", "two", "three", "four"}
-)
-
 func BreakInsert(mapping []idtools.IDMap, extension idtools.IDMap) (result []idtools.IDMap) {
 	result = breakInsert(mapping, extension)
 	result = sortAndMergeConsecutiveMappings(result)
@@ -485,15 +481,6 @@ func TestGetAvailableIDRanges(t *testing.T) {
 	assert.Equal(t, expectedResult, result)
 }
 
-func TestStringInSlice(t *testing.T) {
-	// string is in the slice
-	assert.True(t, StringInSlice("one", sliceData))
-	// string is not in the slice
-	assert.False(t, StringInSlice("five", sliceData))
-	// string is not in empty slice
-	assert.False(t, StringInSlice("one", []string{}))
-}
-
 func TestValidateSysctls(t *testing.T) {
 	strSlice := []string{"net.core.test1=4", "kernel.msgmax=2"}
 	result, _ := ValidateSysctls(strSlice)
@@ -531,7 +518,7 @@ func TestValidateSysctlBadSysctlWithExtraSpaces(t *testing.T) {
 func TestGetIdentityPath(t *testing.T) {
 	name := "p-test"
 	identityPath := GetIdentityPath(name)
-	assert.Equal(t, identityPath, filepath.Join(homedir.Get(), ".local", "share", "containers", "podman", "machine", name))
+	assert.Equal(t, identityPath, filepath.Join(homedir.Get(), ".ssh", name))
 }
 
 func TestCoresToPeriodAndQuota(t *testing.T) {
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 56a26b35be..f3f02da3d8 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -23,7 +23,6 @@ import (
 	"github.com/containers/common/pkg/cgroups"
 	"github.com/containers/podman/v4/libpod/define"
 	"github.com/containers/podman/v4/pkg/inspect"
-	"github.com/containers/podman/v4/pkg/util"
 	. "github.com/containers/podman/v4/test/utils"
 	"github.com/containers/storage/pkg/lockfile"
 	"github.com/containers/storage/pkg/reexec"
@@ -33,6 +32,7 @@ import (
 	. "github.com/onsi/gomega"
 	. "github.com/onsi/gomega/gexec"
 	"github.com/sirupsen/logrus"
+	"golang.org/x/exp/slices"
 	"golang.org/x/sys/unix"
 )
 
@@ -1043,7 +1043,7 @@ func (p *PodmanTestIntegration) PodmanNoEvents(args []string) *PodmanSessionInte
 // MakeOptions assembles all the podman main options
 func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache bool) []string {
 	if p.RemoteTest {
-		if !util.StringInSlice("--remote", args) {
+		if !slices.Contains(args, "--remote") {
 			return append([]string{"--remote", "--url", p.RemoteSocket}, args...)
 		}
 		return args
diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go
index 805c8e1bc9..77a9b15ae2 100644
--- a/test/utils/common_function_test.go
+++ b/test/utils/common_function_test.go
@@ -38,13 +38,6 @@ var _ = Describe("Common functions test", func() {
 		Expect(session.Command.Process).ShouldNot(BeNil(), "SystemExec cannot start a process")
 	})
 
-	It("Test StringInSlice", func() {
-		testSlice := []string{"apple", "peach", "pear"}
-		Expect(StringInSlice("apple", testSlice)).To(BeTrue(), "apple should in ['apple', 'peach', 'pear']")
-		Expect(StringInSlice("banana", testSlice)).ShouldNot(BeTrue(), "banana should not in ['apple', 'peach', 'pear']")
-		Expect(StringInSlice("anything", []string{})).ShouldNot(BeTrue(), "anything should not in empty slice")
-	})
-
 	DescribeTable("Test GetHostDistributionInfo",
 		func(path, id, ver string, empty bool) {
 			txt := fmt.Sprintf("ID=%s\nVERSION_ID=%s", id, ver)
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 205c4edd89..b3f0a17fca 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -404,16 +404,6 @@ func StartSystemExec(command string, args []string) *PodmanSession {
 	return &PodmanSession{session}
 }
 
-// StringInSlice determines if a string is in a string slice, returns bool
-func StringInSlice(s string, sl []string) bool {
-	for _, i := range sl {
-		if i == s {
-			return true
-		}
-	}
-	return false
-}
-
 // tagOutPutToMap parses each string in imagesOutput and returns
 // a map whose key is a repo, and value is another map whose keys
 // are the tags found for that repo. Notice, the first array item will