Sharing SSH key

Viewed 11

What do you think about me created a shared keypair for me and my cofounder to both be able to SSH into a Droplet for ducky.foo? Or is it easy enough for me to just add his own public key to the droplet later?

2 Answers

Creating and sharing SSH key pairs can have significant security implications, so it's important to follow best practices. Here are the considerations and a recommended approach:

Shared Keypair vs Individual Keys

Shared Keypair:

  • Security Risks: Sharing a single keypair between multiple users can lead to security vulnerabilities. If either you or your cofounder’s machine is compromised, the shared keypair could be used to gain unauthorized access to the Droplet.
  • Accountability: With a shared keypair, it's difficult to track actions back to a specific user. This is important for auditing and accountability.
  • Revocation: If the keypair needs to be revoked (e.g., if one user's machine is compromised), both users would be locked out and you would need to deploy a new set of keys.

Individual Keypairs:

  • Security Benefits: Each user having their own keypair means that if one key is compromised, the other keys remain secure.
  • Clear Accountability: Individual keys allow you to determine which user performed specific actions.
  • Easy Management: Adding and revoking an individual’s access is straightforward without affecting others.
  1. Generate Individual SSH Keypairs:

    • Both you and your cofounder should generate your own SSH keypairs on your respective machines.
    • This can typically be done using a command like ssh-keygen -t rsa -b 4096 on Unix-like systems or using software like PuTTYgen on Windows.
  2. Add Public Keys to the Droplet:

    • You can easily add your cofounder’s public key to the Droplet. This can be done by adding their public key to the ~/.ssh/authorized_keys file for the user account on the Droplet.

Steps to Add a Public Key to a Droplet:

  1. Get the Public Key from Your Cofounder:

    • Your cofounder should send you their public key, which is usually found in ~/.ssh/id_rsa.pub (or similar, depending on the key type and name).
  2. Access the Droplet:

    • SSH into your Droplet using your own keypair.
  3. Add the Public Key to Authorized Keys:

    • Open the ~/.ssh/authorized_keys file on the Droplet (create it if it doesn’t exist). You can do this using a command like:
      nano ~/.ssh/authorized_keys
      
    • Paste your cofounder’s public key into this file and save it. Ensure it is pasted on a new line if other keys exist.
  4. Set Correct Permissions:

    • Ensure the .ssh directory and authorized_keys file have the correct permissions:
      chmod 700 ~/.ssh
      chmod 600 ~/.ssh/authorized_keys
      

This approach ensures security, accountability, and ease of management. It allows each user to manage their own keys and credentials independently, reducing the risk and impact of compromised keys.

The joys of SSH key management!

The question is about sharing SSH access to a Droplet (a virtual private server provided by DigitalOcean) for a team of two. The user is considering creating a shared keypair for both users to access the Droplet, and wants to know if this is a good idea or if it's easier to simply add the cofounder's public key to the Droplet later.

Here's a detailed analysis to help make an informed decision:

Pros of sharing a single keypair

  1. Convenience: With a shared keypair, both users can access the Droplet without having to manage multiple keypairs.
  2. Simplified key management: There's only one keypair to manage, which reduces the complexity of managing multiple keys.
  3. Efficient collaboration: Share access can improve collaboration, as both users can easily switch between user accounts or access the Droplet.

Cons of sharing a single keypair

  1. Security concerns: Sharing a single keypair means that if the private key is compromised, both users' access to the Droplet is at risk. This increases the attack surface, making it more challenging to detect malicious activity.
  2. Increased attack surface: With a shared keypair, if one user's account is compromised, the attacker can access the Droplet as the other user.
  3. ** Limited accountability**: It can be challenging to track which user performed specific actions on the Droplet.

Pros of adding the cofounder's public key

  1. Stronger security: By adding the cofounder's public key, you're reducing the attack surface and increasing security, as each user has their own private key.
  2. Accountability: With separate accounts and keys, it's clearer which user performed specific actions on the Droplet.
  3. Better key management: Managing separate keys allows for more granular access control and easier revocation of access if needed.

Cons of adding the cofounder's public key

  1. Increased complexity: Managing multiple keypairs means more complexity and potential errors.
  2. Additional setup: Adding the cofounder's public key requires more configuration and setup.

Conclusion:

While sharing a single keypair might seem convenient, it compromises security and increases the attack surface. It's recommended to add the cofounder's public key to the Droplet, providing stronger security, better accountability, and more granular access control. Additionally, managing separate keypairs allows for easier revocation of access if needed.

If you're concerned about the increased complexity, consider using a password manager or a key management tool to simplify key management. It's essential to balance convenience with security when managing SSH access.

In the end, the decision to share a single keypair or manage separate keys depends on the specific needs and requirements of your team. Weigh the pros and cons carefully to make an informed decision that balances security, convenience, and collaboration.