class PrivateKeyUtils {

    private static final String KEY_PATH = System.getProperty("user.home") + "/.ssh";

    /**
     * write private key to ~/.ssh, filename is ~/.ssh/id_rsa_${host}
     * @param host   host
     * @param keyStr key string
     * @return key file path
     * @throws IOException if ~/.ssh is not exist and create dir error
     */
    public static String writePrivateKey(String host, String keyStr) throws IOException {<FILL_FUNCTION_BODY>}

}

        var sshPath = Paths.get(KEY_PATH);
        if (!Files.exists(sshPath)) {
            Files.createDirectories(sshPath);
        }
        var keyPath = Paths.get(KEY_PATH, "id_rsa_" + host);
        if (!Files.exists(keyPath)) {
            Files.writeString(keyPath, keyStr);
        } else {
            var oldKey = Files.readString(keyPath);
            if (!Objects.equals(oldKey, keyStr)) {
                Files.writeString(keyPath, keyStr);
            }
        }
        return keyPath.toString();
    
<no_super_class>