Need help with a linux script i wrote. it looks me out of my vm after i have run it

shh keys might be the problem

Welcome to the forums. A few more details would go a long way to helping you.

In Linux systems, SSH access is highly sensitive to file integrity and permissions. If a script alters critical components such as SSH keys, file permissions, or authentication settings, it can immediately prevent further access.

Most Likely Causes:

1. Incorrect SSH Key Configuration

If the script overwrites or removes the ~/.ssh/authorized_keys file, the server can no longer authenticate the user.

This results in errors such as:

Permission denied (publickey)

2. Broken File Permissions

SSH requires strict permissions (e.g., private keys must not be publicly accessible).

If permissions are too open (e.g., 0777), SSH will reject the key entirely

3. Ownership Issues

  • Critical SSH directories (like /var/run/sshd or -/.ssh) must be owned by the correct user (often root or the account owner).

  • Incorrect ownership can cause SSH login failures.

4. Configuration Changes

The script may have modified/etc/ssh/sshd_config, for example:

  • disabling password authentication

  • disabling root login

  • restricting access

Any of these changes can immediately block access.

The issue is a classic case of “locking oneself out of a system”, where a script unintentionally breaks SSH authentication by modifying keys, permissions, or configuration.