diff --git a/substrate/core/network-libp2p/src/secret.rs b/substrate/core/network-libp2p/src/secret.rs
index f2a501eafc2745343def6a30cef6ed4a328d91c7..17bd053955e5bcb0f4e5ed50b18affde9c9274bb 100644
--- a/substrate/core/network-libp2p/src/secret.rs
+++ b/substrate/core/network-libp2p/src/secret.rs
@@ -42,6 +42,7 @@ pub fn obtain_private_key(
 			.map_err(|err| IoError::new(IoErrorKind::InvalidData, err))
 	} else {
 		if let Some(ref path) = net_config_path {
+			fs::create_dir_all(Path::new(path))?;
 			// Try fetch the key from a the file containing the secret.
 			let secret_path = Path::new(path).join(SECRET_FILE);
 			match load_private_key_from_file(&secret_path) {