mcp-ssh-manager 3.8.3 → 3.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +21 -10
- package/examples/{backup-workflow.js → backup-workflow.md} +129 -147
- package/package.json +4 -2
- package/scripts/setup-hooks.sh +16 -7
- package/scripts/validate.sh +23 -13
- package/server.json +2 -2
- package/src/backup-manager.js +68 -61
- package/src/config-loader.js +7 -4
- package/src/database-manager.js +2 -19
- package/src/health-monitor.js +20 -11
- package/src/index.js +21 -6
- package/src/logger.js +41 -2
- package/src/shell-quote.js +46 -0
- package/src/ssh-key-manager.js +11 -6
package/src/ssh-key-manager.js
CHANGED
|
@@ -154,9 +154,14 @@ export function removeHostKey(host, port = 22) {
|
|
|
154
154
|
*/
|
|
155
155
|
export async function addHostKey(host, port = 22, keyData = null) {
|
|
156
156
|
try {
|
|
157
|
-
// Backup current known_hosts
|
|
158
|
-
|
|
157
|
+
// Backup current known_hosts. Copy first and treat "not there" as nothing
|
|
158
|
+
// to back up, rather than checking then copying: between the two calls the
|
|
159
|
+
// file can be replaced, and the check adds a race without preventing the
|
|
160
|
+
// failure it appears to guard against.
|
|
161
|
+
try {
|
|
159
162
|
fs.copyFileSync(KNOWN_HOSTS_PATH, KNOWN_HOSTS_BACKUP);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error.code !== 'ENOENT') throw error;
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
// If no key data provided, fetch it
|
|
@@ -168,11 +173,11 @@ export async function addHostKey(host, port = 22, keyData = null) {
|
|
|
168
173
|
keyData = fingerprints.map(fp => fp.fullKey).join('\n');
|
|
169
174
|
}
|
|
170
175
|
|
|
171
|
-
// Ensure .ssh directory exists
|
|
176
|
+
// Ensure .ssh directory exists. No existsSync guard: mkdirSync with
|
|
177
|
+
// recursive:true is already a no-op on an existing directory, and checking
|
|
178
|
+
// first only opens a window where the directory can change underneath us.
|
|
172
179
|
const sshDir = path.dirname(KNOWN_HOSTS_PATH);
|
|
173
|
-
|
|
174
|
-
fs.mkdirSync(sshDir, { mode: 0o700, recursive: true });
|
|
175
|
-
}
|
|
180
|
+
fs.mkdirSync(sshDir, { mode: 0o700, recursive: true });
|
|
176
181
|
|
|
177
182
|
// Append to known_hosts
|
|
178
183
|
fs.appendFileSync(KNOWN_HOSTS_PATH, keyData + '\n');
|