diff --git a/src/api/ssh_keys_post.c b/src/api/ssh_keys_post.c
index 08fd28f2628463ca8530e238beb4f3f434974e24..30633c144cb5c25504cb9d9e9201429e9493e90d 100644
--- a/src/api/ssh_keys_post.c
+++ b/src/api/ssh_keys_post.c
@@ -41,13 +41,12 @@ int callback_ssh_keys_post(const struct _u_request * request,
         return send_simple_response(response, 400, "error", "missing ssh-key");
     }
 
+    // add cryptops-client command to ssh-key
     char * ssh_key_with_command;
-
     add_ssh_command(&ssh_key_with_command, ssh_key);
 
-    asprintf(&ssh_key_with_command, "%s\n", ssh_key_with_command);
-
     // Write SSH key to file
+    asprintf(&ssh_key_with_command, "%s\n", ssh_key_with_command);
     fprintf(authorized_keys, ssh_key_with_command);
     fclose(authorized_keys);
 
diff --git a/src/api/ssh_keys_put.c b/src/api/ssh_keys_put.c
index 0af4782d6eef73eadd5eca0a5c185023333df769..8e9bec0a8943874dcd07945db60d6555bc478201 100644
--- a/src/api/ssh_keys_put.c
+++ b/src/api/ssh_keys_put.c
@@ -50,7 +50,12 @@ int callback_ssh_keys_put(const struct _u_request * request,
         return send_simple_response(response, 400, "error", "missing ssh-key");
     }
 
-    r = replace_ssh_key(id, ssh_key);
+    // add cryptops-client command to ssh-key
+    char * ssh_key_with_command;
+    add_ssh_command(&ssh_key_with_command, ssh_key);
+
+    r = replace_ssh_key(id, ssh_key_with_command);
+
     if (r < 0)
     {
         if (r == -1)