Generate a Telegram String Session from your account using any of three tools:
| Folder | Language | Library |
|---|---|---|
go-session/ |
Go | gogram |
telethon-session/ |
Python | Telethon |
pyrogram-session/ |
Python | Pyrogram |
A String Session lets your userbot or bot script log in as your Telegram account on a VPS without needing OTP every time.
- Open https://my.telegram.org/apps
- Log in with your Telegram phone number
- Create a new app (any name is fine)
- Copy your App ID (a number like
12345678) and App Hash (32-char hex string)
git clone https://github.com/Badmunda05/TgSessionGencd ~/TgSessionGen/pyrogram-session
pip3 install -r requirements.txt
python3 session_gen.pyEnter your API ID: 12345678
Enter your API Hash: abcdef1234567890abcdef1234567890
🔗 Connecting to Telegram …
Enter your phone number (e.g. +919876543210): +919876543210
Enter the OTP code from your Telegram app: 55123
Enter your 2FA password (if enabled): ••••••••
✅ YOUR STRING SESSION (Pyrogram)
BQHBfTsAxx_NOTREAL_xxxxxxxxxxxxxxxxxxxxxxxxxxxx...
💾 Session saved to: pyrogram_session.txt
👤 Name: John Doe | @johndoe | ID: 123456789
cd ~/TgSessionGen/telethon-session
pip3 install -r requirements.txt
python3 session_gen.pysudo apt update && sudo apt install -y golang-go
go version # should show go1.21+wget https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrccd ~/TgSessionGen/go-session
go mod tidy
go run main.gocd ~/TgSessionGen/go-session
go build -o session-gen main.go
./session-gensudo apt update && sudo apt install -y python3 python3-pip git
git clone https://github.com/Badmunda05/TgSessionGen
cd ~/TgSessionGen/pyrogram-session
pip3 install -r requirements.txt
python3 session_gen.pysudo apt update && sudo apt install -y python3 python3-pip git
git clone https://github.com/Badmunda05/TgSessionGen
cd ~/TgSessionGen/telethon-session
pip3 install -r requirements.txt
python3 session_gen.pysudo apt update && sudo apt install -y golang-go git
git clone https://github.com/Badmunda05/TgSessionGen
cd ~/TgSessionGen/go-session
go mod tidy
go run main.gofrom pyrogram import Client
app = Client(
"mybot",
api_id=12345678,
api_hash="your_api_hash",
session_string="YOUR_PYROGRAM_SESSION_STRING",
)
async def main():
async with app:
me = await app.get_me()
print(f"Logged in as: {me.first_name}")
import asyncio
asyncio.run(main())from telethon import TelegramClient
from telethon.sessions import StringSession
client = TelegramClient(
StringSession("YOUR_TELETHON_SESSION_STRING"),
api_id=12345678,
api_hash="your_api_hash",
)
async def main():
await client.start()
me = await client.get_me()
print(f"Logged in as: {me.first_name}")
import asyncio
asyncio.run(main())package main
import (
"fmt"
"github.com/amarnathcjd/gogram/telegram"
)
func main() {
client, _ := telegram.NewClient(telegram.ClientConfig{
AppID: 12345678,
AppHash: "your_api_hash",
StringSession: "YOUR_GOGRAM_SESSION_STRING",
})
client.Conn()
me, _ := client.GetMe()
fmt.Println("Logged in as:", client.JSON(me, true))
client.Idle()
}TgSessionGen/
├── go-session/
│ ├── main.go ← Go session generator (GoGram)
│ └── go.mod ← Go module file
├── telethon-session/
│ ├── session_gen.py ← Python session generator (Telethon)
│ └── requirements.txt
├── pyrogram-session/
│ ├── session_gen.py ← Python session generator (Pyrogram)
│ └── requirements.txt
├── .gitignore
└── README.md
| Problem | Fix |
|---|---|
go: command not found |
Install Go — see Option 3 above |
ModuleNotFoundError: pyrogram |
pip3 install pyrogram tgcrypto |
ModuleNotFoundError: telethon |
pip3 install telethon |
| OTP not arriving | Check Telegram app — code comes as a message from Telegram |
PHONE_NUMBER_INVALID |
Use full format: +919876543210 |
API_ID_INVALID |
Double-check App ID and Hash from my.telegram.org |
AUTH_KEY_UNREGISTERED |
Session expired — generate a new one |
| 2FA prompt | Enter your Telegram Two-Step Verification password |
go mod tidy fails |
Check internet connection |
- Never share your session string — it gives full access to your account
- Never push it to GitHub — it's already in
.gitignore - Use environment variables when deploying bots:
export SESSION="your_session_string"import os
SESSION = os.environ["SESSION"]MIT — free to use, modify, and distribute.