Skip to content

Commit 1fe5f88

Browse files
committed
Create .ssh dir if not exsit
Under image mode, the ~/.ssh dir is created automatically when execute ssh-keygen, so create it if not exsit Signed-off-by: Lili Zhu <lizhu@redhat.com>
1 parent e66fdb3 commit 1fe5f88

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

virttest/ssh_key.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,25 @@ def get_public_key(client_user=None):
6565
'ssh-keygen -t rsa -q -N "" -f %s' % rsa_private_key_path, shell=True
6666
)
6767
else:
68-
process.system(
69-
"su - %s -c 'ssh-keygen -t rsa -q -N \"\" -f %s'"
70-
% (client_user, rsa_private_key_path),
71-
shell=True,
72-
)
68+
try:
69+
process.system(
70+
"su - %s -c 'ssh-keygen -t rsa -q -N \"\" -f $HOME/.ssh/id_rsa'"
71+
% client_user,
72+
shell=True,
73+
)
74+
except Exception as e:
75+
if "No such file or directory" in str(e):
76+
LOG.info("Creating directory %s", ssh_conf_path)
77+
os.makedirs(ssh_conf_path, mode=0o700)
78+
process.run("chown -R %s:%s %s" %
79+
(client_user, client_user, ssh_conf_path), shell=True)
80+
process.system(
81+
"su - %s -c 'ssh-keygen -t rsa -q -N \"\" -f $HOME/.ssh/id_rsa'"
82+
% client_user,
83+
shell=True,
84+
)
85+
else:
86+
raise
7387
public_key_path = rsa_public_key_path
7488

7589
public_key = open(public_key_path, "r")

0 commit comments

Comments
 (0)