- Создание токена персонального доступа для командной строки
- Создание токена
- Использование токена в командной строке
- Creating a personal access token
- Create a Github Personal Access Token and SSH for Your Github Repository
- Github Personal Access Token and SSH
- Create the PAT
- Add token to git
- Switch from HTTPS to SSH URL
- About authentication to GitHub
- Help us make these docs great!
Создание токена персонального доступа для командной строки
Вы можете создать токен доступа и использовать его вместо пароля при выполнении операций Git через HTTPS с Git в командной строке или API.
Для аутентификации в GitHub требуется токен персонального доступа в следующих ситуациях:
- Когда вы используете двухфакторную аутентификацию
- Для доступа к защищенному контенту в организации, использующей единый вход SAML (SSO). Токены, используемые с организациями, использующими SAML SSO, должны быть авторизованы.
Создание токена
1) Проверьте свой адрес электронной почты , если он еще не подтвержден.
2)В правом верхнем углу любой страницы щелкните фотографию своего профиля и нажмите «Settings» .
3) В левой боковой панели нажмите «Developer settings»
4) В левой боковой панели нажмите «Personal access tokens» и затем чтобы создать новый токен нажмите «Generate new token»
5) Задайте маркеру описание и выберите область действия или разрешения, которые нужно предоставить этому токену. Чтобы использовать маркер для доступа к репозиториям из командной строки, выберите repo.
6) Нажмите «Generate token», чтобы создать токен.
7) Скопируйте полученный токен в буфер обмена для следующего использования.
Использование токена в командной строке
Теперь, с помощью токена, вы можете ввести его вместо пароля при выполнении операций Git через HTTPS.
Например, в командной строке вы должны ввести следующее:
Источник
Creating a personal access token
You should create a personal access token to use in place of a password with the command line or with the API.
Note: If you use GitHub CLI to authenticate to GitHub on the command line, you can skip generating a personal access token and authenticate via the web browser instead. For more information about authenticating with GitHub CLI, see gh auth login .
Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line.
If you want to use a PAT to access resources owned by an organization that uses SAML SSO, you must authorize the PAT. For more information, see «About authentication with SAML single sign-on» and «Authorizing a personal access token for use with SAML single sign-on.»
As a security precaution, GitHub automatically removes personal access tokens that haven’t been used in a year. To provide additional security, we highly recommend adding an expiration to your personal access tokens.
A token with no assigned scopes can only access public information. To use your token to access repositories from the command line, select repo . For more information, see “Available scopes”.
Creating a token
Verify your email address, if it hasn’t been verified yet.
In the upper-right corner of any page, click your profile photo, then click Settings.
In the left sidebar, click Developer settings.
In the left sidebar, click Personal access tokens.
Click Generate new token.
Give your token a descriptive name.
To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.
Select the scopes, or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.
Click Generate token.
Warning: Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.
To use your token to authenticate to an organization that uses SAML SSO, authorize the token for use with a SAML single-sign-on organization.
Using a token on the command line
Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.
For example, on the command line you would enter the following:
Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.
If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.
Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client. Git will temporarily store your credentials in memory until an expiry interval has passed. You can also store the token in a plain text file that Git can read before every request. For more information, see «Caching your GitHub credentials in Git.»
Источник
Create a Github Personal Access Token and SSH for Your Github Repository
Github Personal Access Token and SSH
Basic authentication is the use of username and password for authentication. For sometime Github will accept Basic authentication, the use of username and password , to access repositories on Github — to clone, push and pull. The Basic authentication will be deprecated very soon this year, 2021.
Github also allows:
- Username and password with two-factor authentication
- Personal access token (PAT)
- SSH key
Create the PAT
The PAT can only be used over HTTPS Git operations
- On Github, signup if you don’t have an account or login if you already do have one
- At the top right corner, click on your avatar and click on Settings from the drop-down
- On the left side of your Setting Profile page, click on Developer settings
- Click on Personal access token on the next page
- At the right, click on Generate token
- Give the token a name or description and check some privileges you want to give to the token
- Click Generate token , a green button at the bottom of the page
- Copy the token and save it somewhere safely (It will still be there when you check it)
- If the token is forgotten or you could not save it, regenerate it.
Add token to git
vscode is my go-to text editor for my all-round development. Entering the username and token every time is a nuisance. We would add the token globally to git. For a specific application, we can add the token locally. The token would be used as the password.
Reminder
If this was your first time actually using git then you have to set your email and username . git config —global user.email «your@example.com» and git config —global user.name «Your Name» .
- git config —global credential.helper store
- Now clone, push or pull with username and copied token instead of the password
- For the sake of testing, let’s create a dummy repo on Github. Choose the default settings. (Do not close the page or the browser)
- I am on ubuntu so I will install ssh on ubuntu.
- Update and install openssh-server : sudo apt update then sudo apt install openssh-server
- sudo systemctl status ssh to check the ssh status then hit q to get back to the terminal
- sudo ufw allow ssh , will open the ssh port. This enables us to connect to our Ubuntu system via SSH from any remote machine.
- sudo systemctl disable —now ssh to disable ssh and sudo systemctl enable —now ssh to enable ssh
- Generate ssh key, ssh-keygen -t ed25519 -C «your_email@example.com» .
- Hit enter to use the default settings for the file name/path to save your key
- Enter and hit enter for the passphrase and reenter the passphrase and hit enter again
- Start the ssh-agent in the background to add add key to ssh-client : eval «$(ssh-agent -s)»
- ssh-add
/.ssh/id_ed25519 then enter the passphrase used initially to add key to client
/.ssh/id_ed25519.pub will open the public key in gedit. Copy it.
Switch from HTTPS to SSH URL
Say you have the repo already using HTTPS then you have to change the URL on your local server.
- HTTPS url: https://github.com/username/dummyrepo.git
- SSH url: git@github.com:username/dummyrepo.git
check the git url, git remote -v which will display
- origin https://github.com/username/dummyrepo.git (fetch)
- origin https://github.com/username/dummyrepo.git (push)
to change from HTTPS to SSH, git remote set-url it@github.com:username/dummyrepo.git
check the git url verify the changes, git remote -v
Источник
About authentication to GitHub
You can securely access your account’s resources by authenticating to GitHub, using different credentials depending on where you authenticate.
About authentication to GitHub
To keep your account secure, you must authenticate before you can access certain resources on GitHub. When you authenticate to GitHub, you supply or confirm credentials that are unique to you to prove that you are exactly who you declare to be.
You can access your resources in GitHub in a variety of ways: in the browser, via GitHub Desktop or another desktop application, with the API, or via the command line. Each way of accessing GitHub supports different modes of authentication.
- Username and password with two-factor authentication
- Personal access token
- SSH key
Authenticating in your browser
You can authenticate to GitHub in your browser in different ways.
If you’re a member of an enterprise with managed users, you will authenticate to GitHub in your browser using your IdP. For more information, see «Authenticating as a managed user». If you’re not a member of an enterprise with managed users, you will authenticate using your browser on GitHub.com.
Username and password only
- You’ll create a password when you create your user account on GitHub. We recommend that you use a password manager to generate a random and unique password. For more information, see «Creating a strong password.»
Two-factor authentication (2FA) (recommended)
- If you enable 2FA, we’ll also prompt you to provide a code that’s generated by an application on your mobile device or sent as a text message (SMS) after you successfully enter your username and password. For more information, see «Accessing GitHub using two-factor authentication.»
- In addition to authentication with a mobile application or a text message, you can optionally add a secondary method of authentication with a security key using WebAuthn. For more information, see «Configuring two-factor authentication using a security key.»
Authenticating with GitHub Desktop
You can authenticate with GitHub Desktop using your browser. For more information, see «Authenticating to GitHub.»
Authenticating with the API
You can authenticate with the API in different ways.
- Personal access tokens
- In limited situations, such as testing, you can use a personal access token to access the API. Using a personal access token enables you to revoke access at any time. For more information, see «Creating a personal access token.»
- Web application flow
- For OAuth Apps in production, you should authenticate using the web application flow. For more information, see «Authorizing OAuth Apps.»
- GitHub Apps
- For GitHub Apps in production, you should authenticate on behalf of the app installation. For more information, see «Authenticating with GitHub Apps.»
Authenticating with the command line
You can access repositories on GitHub from the command line in two ways, HTTPS and SSH, and both have a different way of authenticating. The method of authenticating is determined based on whether you choose an HTTPS or SSH remote URL when you clone the repository. For more information about which way to access, see «About remote repositories.»
You can work with all repositories on GitHub over HTTPS, even if you are behind a firewall or proxy.
If you authenticate with GitHub CLI, you can either authenticate with a personal access token or via the web browser. For more information about authenticating with GitHub CLI, see gh auth login .
If you authenticate without GitHub CLI, you must authenticate with a personal access token. When Git prompts you for your password, enter your personal access token (PAT) instead. Password-based authentication for Git has been removed, and using a PAT is more secure. For more information, see «Creating a personal access token.» Every time you use Git to authenticate with GitHub, you’ll be prompted to enter your credentials to authenticate with GitHub, unless you cache them a credential helper.
You can work with all repositories on GitHub over SSH, although firewalls and proxys might refuse to allow SSH connections.
If you authenticate with GitHub CLI, the CLI will find SSH public keys on your machine and will prompt you to select one for upload. If GitHub CLI does not find a SSH public key for upload, it can generate a new SSH public/private keypair and upload the public key to your GitHub account. Then, you can either authenticate with a personal access token or via the web browser. For more information about authenticating with GitHub CLI, see gh auth login .
If you authenticate without GitHub CLI, you will need to generate an SSH public/private keypair on your local machine and add the public key to your GitHub account. For more information, see «Generating a new SSH key and adding it to the ssh-agent.» Every time you use Git to authenticate with GitHub, you’ll be prompted to enter your SSH key passphrase, unless you’ve stored the key.
Authorizing for SAML single sign-on
To use a personal access token or SSH key to access resources owned by an organization that uses SAML single sign-on, you must also authorize the personal token or SSH key. For more information, see «Authorizing a personal access token for use with SAML single sign-on» or «Authorizing an SSH key for use with SAML single sign-on.»
GitHub’s token formats
GitHub issues tokens that begin with a prefix to indicate the token’s type.
Token type | Prefix | More information |
---|---|---|
Personal access token | ghp_ | «Creating a personal access token» |
OAuth access token | gho_ | «Authorizing OAuth Apps» |
User-to-server token for a GitHub App | ghu_ | «Identifying and authorizing users for GitHub Apps» |
Server-to-server token for a GitHub App | ghs_ | «Authenticating with GitHub Apps» |
Refresh token for a GitHub App | ghr_ | «Refreshing user-to-server access tokens» |
Help us make these docs great!
All GitHub docs are open source. See something that’s wrong or unclear? Submit a pull request.
Источник