Here is step by step on connecting Cursor to Replit and some good rules to add.
Step 1: Generate SSH Keys in Replit
Open the Shell/Terminal in your Replit project and generate the keys:
bash
ssh-keygen -t ed25519 -C "your_email@example.com"
When prompted:
Verify creation:
bash
ls ~/.ssh/
You should see: id_ed25519 (private) and id_ed25519.pub (public)
Step 2: View Your Keys
Public key (safe to share):
bash
cat ~/.ssh/id_ed25519.pub
Private key (keep secret):
bash
cat ~/.ssh/id_ed25519
Step 3: Save Keys to Your Computer
On Windows:
- Create .ssh folder:
cmd
mkdir %USERPROFILE%\.ssh
-
Copy keys from Replit (use cat commands above)
-
Save files:
-
Open Notepad/VS Code
-
Paste private key → Save as C:\Users\YourUsername\.ssh\replit (no extension, “All Files”)
-
Paste public key → Save as C:\Users\YourUsername\.ssh\replit.pub
-
Set permissions (PowerShell as Admin):
powershell
icacls "%USERPROFILE%\.ssh\replit" /inheritance:r /grant:r "%username%:R"
On Linux/Mac:
- Create .ssh folder:
bash
mkdir -p ~/.ssh
-
Copy keys from Replit (use cat commands above)
-
Save files:
bash
nano ~/.ssh/replit # Paste private key, Ctrl+X to save
nano ~/.ssh/replit.pub # Paste public key, Ctrl+X to save
- Set permissions:
bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/replit
chmod 644 ~/.ssh/replit.pub
Step 4: Add Keys to Replit Account
- Copy your public key from Replit:
bash
cat ~/.ssh/id_ed25519.pub
-
Go to Replit Account Settings:
-
Paste and save:
Step 5: Create (or Update) Your SSH Config File
On Windows:
- Create the file:
cmd
notepad %USERPROFILE%\.ssh\config
Or use VS Code:
cmd
code %USERPROFILE%\.ssh\config
```
2. Paste this configuration:
```
Host *.replit.dev
Port 22
IdentityFile ~/.ssh/replit
StrictHostKeyChecking no
UserKnownHostsFile NUL
Host *.replit.co
Port 22
IdentityFile ~/.ssh/replit
StrictHostKeyChecking no
UserKnownHostsFile NUL
- Save and close (File → Save in Notepad, or Ctrl+S in VS Code)
On Linux/Mac:
- Create the file:
bash
nano ~/.ssh/config
Or use your preferred editor:
bash
vim ~/.ssh/config
# or
code ~/.ssh/config
```
2. Paste this configuration:
```
Host *.replit.dev
Port 22
IdentityFile ~/.ssh/replit
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
Host *.replit.co
Port 22
IdentityFile ~/.ssh/replit
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
-
Save and exit (Ctrl+X, then Y, then Enter in nano)
-
Set permissions:
bash
chmod 600 ~/.ssh/config
```
Configuration Explained:
- **Host .replit.dev / Host .replit.co: Matches any Replit subdomain
- Port 22: Standard SSH port
- IdentityFile: Path to your private key (update if you named it differently)
- StrictHostKeyChecking no: Skips host verification prompt
- UserKnownHostsFile: NUL on Windows (discards known hosts) / /dev/null on Linux/Mac (discards known hosts)
Notes:
- File must be named exactly
config (no .txt or other extension)
- If you used a different key name, update IdentityFile path accordingly
- The config file is read by SSH client when connecting to matching hosts
- Both .replit.dev and .replit.co domains are now supported
Step 6: Connect to Cursor
In Replit, open the Developer Tab and go to Connect. You should be able to click on Launch Cursor now.
Common Issues:
- Incorrect permissions on the private key
- Private key has an extension like .txt
Optimizing Cursor for Replit Projects
Once you have Cursor connected to your project, you’re ready to get started. There are a few additions that make Cursor more powerful and capable when working with your Replit project.
1. Create a cursorvars.md file
Create a file called cursorvars.md and add an exclude for it in the .gitignore file, then add:
DATABASE_URL: [get your database URL from Replit secrets]
PREVIEWURL: [get the URL to your app]
Add any other secrets that it might need when writing code… I put my OpenAI ones.
2. Create a cursor_scripts folder
Create a folder in your project called cursor_scripts and add that to your .gitignore file also. This is where you want Cursor to put its temp scripts, and you don’t want Replit agents getting confused.
3. Add Cursor Rules
Now in Cursor, add a couple of rules explaining what you did:
Rule 1:
This is a Replit project. When creating scripts to cleanup or update the database, keep those in the root cursor_scripts folder. Also in the project there is a file called cursorvars.md and in that I will put various Replit environmental variables for you to be aware of, especially DATABASE_URL. You can use that value to run direct database commands and updates. Do not use db:push to make database changes, update the tables using SQL.
Note: This last part is because db:push rarely works even with -force.
Rule 2 - Restart dev server after code changes:
# Restart dev server after code changes
- After applying **any code change** that affects the running app, the AI should **restart the dev server on the remote SSH shell** by running:
```bash
fuser -k 5000/tcp || true
npm run dev
Rule 3 - Auto-Commit (Optional but Recommended)
IMPORTANT: If you don’t want to have to keep switching to Replit and going to the Git tab to commit your changes, you can automate this.
Create another rule (replace YOUREMAILHERE and YOURNAMEHERE):
Auto-commit After Approval
When the user approves or accepts changes made in the session, run the auto-commit script with a descriptive message summarizing the work:
cd /home/runner/workspace && git config user.email “YOUREMAILHERE” && git config user.name “YOURNAMEHERE” && git add -A && git commit -m “Brief description of changes”
Use a concise, descriptive commit message that reflects the main changes (e.g., “Fix tier discounts in POS”, “Add customer data validation”, “Remove dead JWT route”).