LeetCode-Notes
  • Introduction
  • Records of Practice
  • 关于Github 不支持密码问题
  • 面试题
    • 搜索广告
    • 多模态大模型
    • 刷题记录
  • 算法代码实现
  • Python
    • Python 笔记
  • Spark
    • PySpark
    • Spark Issues
    • Spark调优笔记
  • FeatureEngineering
    • Feature Cleaning
    • Feature Selection
    • Feature Transformation
    • Feature Crossing
  • Recommendation Algorithm
    • Recall-and-PreRank
      • Non-Negative Matrix Fatorization(NMF)
      • Fatorization Machine(FM)
      • User-base/Item-base实现
      • 多路召回实现
    • Ranking
      • NeuralFM
      • DeepFM
      • Deep&Cross network (DCN)
    • DeepLearning-Basic
      • Attention
      • Dropout
      • Batch Norm
  • Machine Learning
    • XGBoost
    • Cross Entropy Loss
    • Other models
  • Graph Neural Network
    • GNN-1-Basic
  • Big Data
    • Reservoir Sampling
  • SQL
    • SQL and PySpark functions
    • Query Film Infomation
    • Create, Insert and Alter Actor Table
    • Manage Employment Data
    • Manage Employment Data -2
  • DataStructure
    • Searching
      • Find power
      • 2 Sum All Pair II
      • Two Sum
      • Search in Rotate Array
      • Search In Shifted Sorted Array II
      • Search in 2D array
      • Three Sum with duplicated values
      • Median of Two Sorted Arrays
    • Array
      • Longest Consecutive Subarray
      • Merge Two Array in-place
      • Trapping water
      • Rotate matrix
    • Sorting
      • Merge intervals
      • 排序
      • 最小的k个数
      • Find TopK largest- QuickSelect快速选择 method
      • MergeSort Linkedlist
      • 第K大元素
    • LinkedList
      • Reverse LinkedList I
      • Reverse K-group linked list
      • Detect Start of Cycle
      • HasCycle
      • DetectCycle II
      • 链表的共同节点
      • 链表中倒数第k个节点
      • 删除链表倒数第k个节点
      • 合并两个链表
      • 在排序数组中查找元素的第一个和最后一个位置
      • 删除链表里面重复的元素-1
    • Tree
      • Find Tree height (general iteration method)
      • Check BST and Check CompleteTree
      • ZigZag Order traversal
      • Binary Tree diameter I
      • Maximum Path Sum Binary Tree
      • Maximum Path Sum Binary Tree II
      • Binary Tree Path Sum To Target III
      • Tree diameter 树的直径II
      • Tree ReConstruction
      • Check if B is Subtree of A
      • The Kth smallest in Binary Search Tree
      • 打印Tree的右视图
      • 二叉搜索树的后序遍历序列
      • 重建二叉树
      • 判断二叉树是否对称
      • Path Sum to Target in Binary Tree
      • Tree-PreOrder-InOrder-PostOrder
    • Heap&Queue
      • Top-K smallest
      • 滑动窗口最大值
      • Find the K-Largest
    • 合并k个已排序的链表
    • String
      • Reverse String
      • 最长不含重复字符的子字符串
      • 最长回文串
      • 最长回文子序列-DP
    • DFS/BFS
      • Number of island
      • Number of Provinces
      • All Permutations of Subsets without duplication
      • All Permutations of Subsets with duplication
      • Combinations Of Coins
      • All Subset I (without fixing size of subset, without order, without duplication)
      • All Subset of K size without duplication II
      • All Subset of K size III (with duplication without considering order)
      • All Permutation II (with duplication and consider order)
      • Factor Combination-质数分解
    • DynamicProgramming
      • DP-解题过程
      • Find Continuous Sequence Sum to Target
      • 1800. Maximum Ascending Subarray Sum
      • NC91 最长上升子序列
      • 查找string的编码方式个数
      • Maximum Product
      • Longest Common Substring
      • Longest Common Substring-II
      • minEditCost
      • Backpack I
      • Array Hopper I
      • Minimum distance between strings
      • 最大正方形
  • Big Data Algorithms
    • Big Data Processing Algorithms
      • Reservior Sampling
      • Shuffle
      • MapReduce
      • Bloom Filter
      • BitMap
      • Heap For Big Data
Powered by GitBook
On this page
  • 1、问题 -1
  • 解决方法
  • 2、问题-2

Was this helpful?

关于Github 不支持密码问题

1、问题 -1

现在github不支持密码输入来push, pull

// Some code
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/wenkangwei/Project_TextImage_Generator.git/'

解决方法

(推荐)方法 1:使用 SSH 替代 HTTPS

SSH 是一种更安全的认证方式,推荐使用。

步骤:

  1. 生成 SSH 密钥(如果还没有):

    bash复制

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    按提示操作,生成密钥对(id_rsa 和 id_rsa.pub)。

  2. 将公钥添加到 GitHub:

    • 复制公钥内容:

      bash复制

      cat ~/.ssh/id_rsa.pub
    • 登录 GitHub,进入 Settings > SSH and GPG keys,点击 New SSH key,粘贴公钥并保存。

  3. 测试 SSH 连接:

    bash复制

    ssh -T git@github.com

    如果看到 Hi username!,说明 SSH 配置成功。

  4. 使用 SSH 克隆仓库: 将 HTTPS URL 替换为 SSH URL。例如:

    bash复制

    git clone git@github.com:wenkangwei/Project_TextImage_Generator.git

方法 2:使用 Personal Access Token 替代密码

如果你仍然想使用 HTTPS,可以用 Personal Access Token(PAT)替代密码。

步骤:

  1. 生成 Personal Access Token:

    • 登录 GitHub,进入 Settings > Developer settings > Personal access tokens。

    • 点击 Generate new token。

    • 选择需要的权限(例如 repo 和 workflow)。

    • 点击 Generate token,复制生成的 Token(只会显示一次,请妥善保存)。

  2. 使用 Token 克隆仓库: 在克隆时,将密码替换为 Token。例如:

    bash复制

    git clone https://<TOKEN>@github.com/wenkangwei/Project_TextImage_Generator.git

    将 <TOKEN> 替换为你的实际 Token。

  3. 保存 Token 以避免重复输入: 你可以将 Token 保存到 Git 的凭据管理器中:

    bash复制

    git config --global credential.helper store

    然后运行一次克隆或推送命令,输入用户名和 Token,Git 会将其保存。


方法 3:更新远程仓库 URL

如果你已经克隆了仓库,但使用的是 HTTPS,可以将其更新为 SSH 或使用 Token 的 HTTPS。

更新为 SSH:

  1. 查看当前远程仓库 URL:

    bash复制

    git remote -v

    输出示例:

    复制

    origin  https://github.com/wenkangwei/Project_TextImage_Generator.git (fetch)
    origin  https://github.com/wenkangwei/Project_TextImage_Generator.git (push)
  2. 更新为 SSH URL:

    bash复制

    git remote set-url origin git@github.com:wenkangwei/Project_TextImage_Generator.git
  3. 验证更新:

    bash复制

    git remote -v

    输出示例:

    复制

    origin  git@github.com:wenkangwei/Project_TextImage_Generator.git (fetch)
    origin  git@github.com:wenkangwei/Project_TextImage_Generator.git (push)

更新为使用 Token 的 HTTPS:

  1. 更新 URL:

    bash复制

    git remote set-url origin https://<TOKEN>@github.com/wenkangwei/Project_TextImage_Generator.git

    将 <TOKEN> 替换为你的实际 Token。

  2. 验证更新:

    bash复制

    git remote -v

总结

  • 推荐使用 SSH:更安全且无需每次输入凭据。

  • 如果坚持使用 HTTPS,请使用 Personal Access Token 替代密码。

  • 更新远程仓库 URL 可以避免每次手动输入凭据。

2、问题-2

remote: error: GH013: Repository rule violations found for refs/heads/main. remote: remote: - GITHUB PUSH PROTECTION remote: ————————————————————————————————————————— remote: Resolve the following violations before pushing again remote: remote: - Push cannot contain secrets remote:

这个错误提示表明 GitHub 的 Push Protection 功能检测到你的推送内容中可能包含敏感信息(如 API 密钥、密码、Token 等),因此拒绝了推送操作。这是 GitHub 为了保护用户数据安全而引入的功能。


如何解决这个问题

步骤 1:检查推送内容中的敏感信息

  1. 查看 Git 提交记录:

    bash复制

    git log

    找到最近提交的文件和内容。

  2. 检查这些文件中是否包含敏感信息:

    • API 密钥

    • 密码

    • 数据库连接字符串

    • 个人访问令牌(PAT)

    • 其他机密信息

  3. 如果发现敏感信息,继续下一步。


步骤 2:移除敏感信息

  1. 从代码中移除敏感信息:

    • 删除或替换代码中的敏感信息。

    • 例如,将硬编码的 API 密钥替换为环境变量。

  2. 将敏感信息添加到 .gitignore:

    • 如果敏感信息存储在某个文件中(如 .env),确保将该文件添加到 .gitignore 中:

      bash复制

      echo ".env" >> .gitignore
  3. 从 Git 历史记录中移除敏感信息:

    • 如果敏感信息已经提交到了 Git 历史记录中,需要使用 git filter-repo 或 BFG Repo-Cleaner 工具清理历史记录。

    • 示例使用 git filter-repo:

      bash复制

      git filter-repo --replace-text <(echo "OLD_SECRET==>NEW_SECRET")

      将 OLD_SECRET 替换为实际的敏感信息,NEW_SECRET 替换为占位符或空字符串。


步骤 3:重新提交并推送

  1. 提交更改:

    bash复制

    git add .
    git commit -m "Remove sensitive information"
  2. 强制推送(如果需要覆盖远程分支):

    bash复制

    git push --force

步骤 4:使用环境变量管理敏感信息

为了避免将来再次出现类似问题,建议使用环境变量来管理敏感信息。

  1. 将敏感信息存储在环境变量中:

    • 例如,在 .env 文件中:

      复制

      API_KEY=your_api_key_here
    • 在代码中读取环境变量:

      python复制

      import os
      api_key = os.getenv("API_KEY")
  2. 确保 .env 文件被添加到 .gitignore 中:

    bash复制

    echo ".env" >> .gitignore
  3. 在本地和服务器上配置环境变量。


步骤 5:禁用 GitHub Push Protection(不推荐)

如果你确认推送内容中没有敏感信息,但仍然被阻止,可以尝试禁用 GitHub 的 Push Protection 功能。

  1. 进入 GitHub 仓库的 Settings > Code security and analysis。

  2. 找到 Push protection,点击 Disable。

注意:禁用 Push Protection 会降低仓库的安全性,不推荐这样做。

PreviousRecords of PracticeNext搜索广告

Last updated 2 months ago

Was this helpful?