How-to-Add-An-SSH-Key-in-Magento-2

How To Add An SSH Key In Magento 2 In Different Ways?

Posted by

SSH (Secure Shell) is a cryptography protocol to help a user sharing the data between two computers (your computer and a remote server) over an unsecured network.

Because of the strong encryption, it can carry out multiple tasks such as remote transfer files, manage networks, and access remote system operation without being afraid of hacking.

Therefore, connecting Magento 2 SSH Key is an excellent way to protect your business online and customers against certain attacks.

What Are SSH Keys?

What-Are-SSH-Keys?

SSH Keys (Secure Socket Shell Keys) are access credentials that are used in the SSH protocol. Generally, SSH uses pair keys: a private key and a public key to secure between remote parties.

A private key is for a user system to attempt to access the remote server. It should remain private because it uses to decrypt information that is transferred in the SSH protocol.

A public key is used to encrypt information, therefore, it can be shared and used by both user and remote system.

To simplify, a private key allows you to transfer your file, and only you can see it. Meanwhile, a public key will public the files that can be seen by anyone at any time.

How To Create SSH Keys Pair?

How-To-Create-SSH-Keys-Pair?

You can generate the SSH Keys Pair on Mac, Linux, and Window systems. With Mac and Linux, you can use the command ssh-keygen to generate a new key pair.

With Windows, you can generate your keys on the server. But, remember deleting the whitespaces.

First, to generate the SSH Keys Pair, run ssh-keygen You will see it looks like this:

laptop1:~ yourname$ ssh-keygen
Generating public/private rsa key pair.

Second, you will choose the location to save your keys.

Enter file in which to save the key

(/Users/yourname/.ssh/id_rsa):

Then, you have to enter your username and password to use for your private key.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

After that, your public and private key will be generated. A name  id_rsa is your private key, and id_rsa.pub is your public key.

Your identification has been saved in

/Users/yourname/.ssh/id_rsa.

Your public key has been saved in

/Users/yourname/.ssh/id_rsa.pub.

How To Create Magento 2 SSH Keys

<?ssh-add -K ~/.ssh/id_rsa

For Windows and Linux:

<?ssh-add ~/.ssh/id_rsa

Test the Magento 2 SSH Key

After adding the Magento 2 Authentication SSH Key for GitHub, make sure to test your keys pair whether it works or not. Firstly, enter the following command:

<?ssh -T git@github.com

Then, click YES when seeing the warning box, displaying it on the screen. You will receive the success message if it works.

If you receive the message error, you can check with some explanations below:

  • Do you connect to the right server? Make sure your connection is right by following the command:
<?$ ssh -vT git@github.com
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Reading configuration data /Users/you/.ssh/config
> debug1: Reading configuration data /etc/ssh_config
> debug1: Applying options for *
> debug1: Connecting to github.com [IP ADDRESS] port 22.
  • You have to use “Git user” instead of using “Github” username. You also verify your connection by the command:
<?$ ssh -T git@github.com
> Hi username! You've successfully authenticated...
  • Check your key by connecting to You can also check that the key is being used by trying to connect to git@github.com:
<?$ ssh -vT git@github.com
> ...
>> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

How To Add a Public SSH Key To The Magento Account?

#1. Using the CLI to add SSH Key

  • Open to your default location you stored your Magento 2 Authentication SSH Key for Git, and log in to your project and add the key:
<?Magento-cloud 
ssh-key:add ~/.ssh/id_rsa.pub
  • In your account, you have to choose and add your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?
  • Copy your SSH Public Key and Login and access the Project Web Interface account.
  • Install your SSH Key in the selected branch.
  • Copy and Paste your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?

#2. Using Magento Cloud CLI to add SSH key

First, you log into the project and list your project IDs:

<?magento-cloud login
>magento-cloud project:list

Then, list SSH into the environments in the project:

<?magento-cloud environment:list -p <project ID>
magento-cloud ssh -p <project ID> -e <environment ID>

#3. Pro Staging and Production SSH Key command

You can add SSH Key in the Pro Staging and Production and use Linux command to manage the system.

Production:

<?ssh <project ID>@<project ID>.ent.magento.cloud

Staging:

<?ssh <project ID>_stg@<project ID>.ent.magento.cloud

How to Generate SSH for Specific Projects, say Github?

#1. Adding a new SSH key to your Github account

  • Copy the SSH Key, remember that do not add any whitespace or newlines
<?$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • Clicking to your account and selecting Setting. You will see SSH and GPG keys, then click to Add New SSH Key.
  • You click Paste the SSH Key that you copied and confirm your Github password after adding your SSH Keys Pair.
How-to-Generate-SSH-for-Specific-Projects-say-Github?

#2. Testing your SSH Keys Pair

  • Open Git Bash and enter the command:
<?$ ssh -T git@github.com
# Attempts to ssh to GitHub
  • You will see the message like this:
<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)?

or:

<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?
  • Then, type YES to see whether your SSH Key on Github works or not. If it runs successfully, you will see this display:
<?> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

#3. Working with SSH Key Passphrases

Someone can access your system if they can access your computer. To ensure more security for your account and website, you can use ssh-agent to save your password, therefore, you do not have to re-enter it.

You can change your password without re-entering the key through the command below:

<?$ ssh-keygen -p
# Start the SSH key creation process
> Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter]
> Key has comment '/Users/you/.ssh/id_rsa'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [One more time for luck]
> Your identification has been saved with the new passphrase.

But if you install your SSH Keys Pair on the Windows, instead of following the command above; you can copy the code below into your Git Shell:

<?env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi 
unset env

Therefore, when you run your Git Bash, you will be required to enter your password:

<?> Initializing new SSH agent...
> succeeded
> Enter passphrase for /c/Users/you/.ssh/id_rsa:
> Identity added: /c/Users/you/.ssh/id_rsa (/c/Users/you/.ssh/id_rsa)
> Welcome to Git (version 1.6.0.2-preview20080923)
>
> Run 'git help git' to display the help index.
> Run 'git help ' to display help for specific commands.

[BONUS] Share Access To Magento Commerce Cloud And GitHub Branches

In Magento 2, you can add SSH Keys to Share access to Magento Commerce Cloud or Share access to GitHub branches.

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

<?ssh-add ~/.ssh/id_rsa

But if you do not have, you can follow some simple steps we present below.

First, enter the email you registered your Github account:

<?ssh-keygen -t rsa

When it displays “Enter a file in which to save the key,”, you click Enter to save your default location to save your Magento 2 SSH Key.

Next, after creating the SSH Keys pair, you will start with ssh-agent:

For Mac and Linux:

<?eval "$(ssh-agent -s)"

For Windows:

<?eval $(ssh-agent -s)

Then, add your Magento 2 SSH Key,

For Mac:

<?ssh-add -K ~/.ssh/id_rsa

For Windows and Linux:

<?ssh-add ~/.ssh/id_rsa

Test the Magento 2 SSH Key

After adding the Magento 2 Authentication SSH Key for GitHub, make sure to test your keys pair whether it works or not. Firstly, enter the following command:

<?ssh -T git@github.com

Then, click YES when seeing the warning box, displaying it on the screen. You will receive the success message if it works.

If you receive the message error, you can check with some explanations below:

  • Do you connect to the right server? Make sure your connection is right by following the command:
<?$ ssh -vT git@github.com
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Reading configuration data /Users/you/.ssh/config
> debug1: Reading configuration data /etc/ssh_config
> debug1: Applying options for *
> debug1: Connecting to github.com [IP ADDRESS] port 22.
  • You have to use “Git user” instead of using “Github” username. You also verify your connection by the command:
<?$ ssh -T git@github.com
> Hi username! You've successfully authenticated...
  • Check your key by connecting to You can also check that the key is being used by trying to connect to git@github.com:
<?$ ssh -vT git@github.com
> ...
>> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

How To Add a Public SSH Key To The Magento Account?

#1. Using the CLI to add SSH Key

  • Open to your default location you stored your Magento 2 Authentication SSH Key for Git, and log in to your project and add the key:
<?Magento-cloud 
ssh-key:add ~/.ssh/id_rsa.pub
  • In your account, you have to choose and add your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?
  • Copy your SSH Public Key and Login and access the Project Web Interface account.
  • Install your SSH Key in the selected branch.
  • Copy and Paste your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?

#2. Using Magento Cloud CLI to add SSH key

First, you log into the project and list your project IDs:

<?magento-cloud login
>magento-cloud project:list

Then, list SSH into the environments in the project:

<?magento-cloud environment:list -p <project ID>
magento-cloud ssh -p <project ID> -e <environment ID>

#3. Pro Staging and Production SSH Key command

You can add SSH Key in the Pro Staging and Production and use Linux command to manage the system.

Production:

<?ssh <project ID>@<project ID>.ent.magento.cloud

Staging:

<?ssh <project ID>_stg@<project ID>.ent.magento.cloud

How to Generate SSH for Specific Projects, say Github?

#1. Adding a new SSH key to your Github account

  • Copy the SSH Key, remember that do not add any whitespace or newlines
<?$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • Clicking to your account and selecting Setting. You will see SSH and GPG keys, then click to Add New SSH Key.
  • You click Paste the SSH Key that you copied and confirm your Github password after adding your SSH Keys Pair.
How-to-Generate-SSH-for-Specific-Projects-say-Github?

#2. Testing your SSH Keys Pair

  • Open Git Bash and enter the command:
<?$ ssh -T git@github.com
# Attempts to ssh to GitHub
  • You will see the message like this:
<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)?

or:

<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?
  • Then, type YES to see whether your SSH Key on Github works or not. If it runs successfully, you will see this display:
<?> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

#3. Working with SSH Key Passphrases

Someone can access your system if they can access your computer. To ensure more security for your account and website, you can use ssh-agent to save your password, therefore, you do not have to re-enter it.

You can change your password without re-entering the key through the command below:

<?$ ssh-keygen -p
# Start the SSH key creation process
> Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter]
> Key has comment '/Users/you/.ssh/id_rsa'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [One more time for luck]
> Your identification has been saved with the new passphrase.

But if you install your SSH Keys Pair on the Windows, instead of following the command above; you can copy the code below into your Git Shell:

<?env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi 
unset env

Therefore, when you run your Git Bash, you will be required to enter your password:

<?> Initializing new SSH agent...
> succeeded
> Enter passphrase for /c/Users/you/.ssh/id_rsa:
> Identity added: /c/Users/you/.ssh/id_rsa (/c/Users/you/.ssh/id_rsa)
> Welcome to Git (version 1.6.0.2-preview20080923)
>
> Run 'git help git' to display the help index.
> Run 'git help ' to display help for specific commands.

[BONUS] Share Access To Magento Commerce Cloud And GitHub Branches

In Magento 2, you can add SSH Keys to Share access to Magento Commerce Cloud or Share access to GitHub branches.

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

<?ssh-add ~/.ssh/id_rsa

But if you do not have, you can follow some simple steps we present below.

First, enter the email you registered your Github account:

<?ssh-keygen -t rsa

When it displays “Enter a file in which to save the key,”, you click Enter to save your default location to save your Magento 2 SSH Key.

Next, after creating the SSH Keys pair, you will start with ssh-agent:

For Mac and Linux:

<?eval "$(ssh-agent -s)"

For Windows:

<?eval $(ssh-agent -s)

Then, add your Magento 2 SSH Key,

For Mac:

<?ssh-add -K ~/.ssh/id_rsa

For Windows and Linux:

<?ssh-add ~/.ssh/id_rsa

Test the Magento 2 SSH Key

After adding the Magento 2 Authentication SSH Key for GitHub, make sure to test your keys pair whether it works or not. Firstly, enter the following command:

<?ssh -T git@github.com

Then, click YES when seeing the warning box, displaying it on the screen. You will receive the success message if it works.

If you receive the message error, you can check with some explanations below:

  • Do you connect to the right server? Make sure your connection is right by following the command:
<?$ ssh -vT git@github.com
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Reading configuration data /Users/you/.ssh/config
> debug1: Reading configuration data /etc/ssh_config
> debug1: Applying options for *
> debug1: Connecting to github.com [IP ADDRESS] port 22.
  • You have to use “Git user” instead of using “Github” username. You also verify your connection by the command:
<?$ ssh -T git@github.com
> Hi username! You've successfully authenticated...
  • Check your key by connecting to You can also check that the key is being used by trying to connect to git@github.com:
<?$ ssh -vT git@github.com
> ...
>> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

How To Add a Public SSH Key To The Magento Account?

#1. Using the CLI to add SSH Key

  • Open to your default location you stored your Magento 2 Authentication SSH Key for Git, and log in to your project and add the key:
<?Magento-cloud 
ssh-key:add ~/.ssh/id_rsa.pub
  • In your account, you have to choose and add your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?
  • Copy your SSH Public Key and Login and access the Project Web Interface account.
  • Install your SSH Key in the selected branch.
  • Copy and Paste your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?

#2. Using Magento Cloud CLI to add SSH key

First, you log into the project and list your project IDs:

<?magento-cloud login
>magento-cloud project:list

Then, list SSH into the environments in the project:

<?magento-cloud environment:list -p <project ID>
magento-cloud ssh -p <project ID> -e <environment ID>

#3. Pro Staging and Production SSH Key command

You can add SSH Key in the Pro Staging and Production and use Linux command to manage the system.

Production:

<?ssh <project ID>@<project ID>.ent.magento.cloud

Staging:

<?ssh <project ID>_stg@<project ID>.ent.magento.cloud

How to Generate SSH for Specific Projects, say Github?

#1. Adding a new SSH key to your Github account

  • Copy the SSH Key, remember that do not add any whitespace or newlines
<?$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • Clicking to your account and selecting Setting. You will see SSH and GPG keys, then click to Add New SSH Key.
  • You click Paste the SSH Key that you copied and confirm your Github password after adding your SSH Keys Pair.
How-to-Generate-SSH-for-Specific-Projects-say-Github?

#2. Testing your SSH Keys Pair

  • Open Git Bash and enter the command:
<?$ ssh -T git@github.com
# Attempts to ssh to GitHub
  • You will see the message like this:
<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)?

or:

<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?
  • Then, type YES to see whether your SSH Key on Github works or not. If it runs successfully, you will see this display:
<?> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

#3. Working with SSH Key Passphrases

Someone can access your system if they can access your computer. To ensure more security for your account and website, you can use ssh-agent to save your password, therefore, you do not have to re-enter it.

You can change your password without re-entering the key through the command below:

<?$ ssh-keygen -p
# Start the SSH key creation process
> Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter]
> Key has comment '/Users/you/.ssh/id_rsa'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [One more time for luck]
> Your identification has been saved with the new passphrase.

But if you install your SSH Keys Pair on the Windows, instead of following the command above; you can copy the code below into your Git Shell:

<?env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi 
unset env

Therefore, when you run your Git Bash, you will be required to enter your password:

<?> Initializing new SSH agent...
> succeeded
> Enter passphrase for /c/Users/you/.ssh/id_rsa:
> Identity added: /c/Users/you/.ssh/id_rsa (/c/Users/you/.ssh/id_rsa)
> Welcome to Git (version 1.6.0.2-preview20080923)
>
> Run 'git help git' to display the help index.
> Run 'git help ' to display help for specific commands.

[BONUS] Share Access To Magento Commerce Cloud And GitHub Branches

In Magento 2, you can add SSH Keys to Share access to Magento Commerce Cloud or Share access to GitHub branches.

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

<?ssh-add -K ~/.ssh/id_rsa

For Windows and Linux:

<?ssh-add ~/.ssh/id_rsa

Test the Magento 2 SSH Key

After adding the Magento 2 Authentication SSH Key for GitHub, make sure to test your keys pair whether it works or not. Firstly, enter the following command:

<?ssh -T git@github.com

Then, click YES when seeing the warning box, displaying it on the screen. You will receive the success message if it works.

If you receive the message error, you can check with some explanations below:

  • Do you connect to the right server? Make sure your connection is right by following the command:
<?$ ssh -vT git@github.com
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Reading configuration data /Users/you/.ssh/config
> debug1: Reading configuration data /etc/ssh_config
> debug1: Applying options for *
> debug1: Connecting to github.com [IP ADDRESS] port 22.
  • You have to use “Git user” instead of using “Github” username. You also verify your connection by the command:
<?$ ssh -T git@github.com
> Hi username! You've successfully authenticated...
  • Check your key by connecting to You can also check that the key is being used by trying to connect to git@github.com:
<?$ ssh -vT git@github.com
> ...
>> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

How To Add a Public SSH Key To The Magento Account?

#1. Using the CLI to add SSH Key

  • Open to your default location you stored your Magento 2 Authentication SSH Key for Git, and log in to your project and add the key:
<?Magento-cloud 
ssh-key:add ~/.ssh/id_rsa.pub
  • In your account, you have to choose and add your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?
  • Copy your SSH Public Key and Login and access the Project Web Interface account.
  • Install your SSH Key in the selected branch.
  • Copy and Paste your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?

#2. Using Magento Cloud CLI to add SSH key

First, you log into the project and list your project IDs:

<?magento-cloud login
>magento-cloud project:list

Then, list SSH into the environments in the project:

<?magento-cloud environment:list -p <project ID>
magento-cloud ssh -p <project ID> -e <environment ID>

#3. Pro Staging and Production SSH Key command

You can add SSH Key in the Pro Staging and Production and use Linux command to manage the system.

Production:

<?ssh <project ID>@<project ID>.ent.magento.cloud

Staging:

<?ssh <project ID>_stg@<project ID>.ent.magento.cloud

How to Generate SSH for Specific Projects, say Github?

#1. Adding a new SSH key to your Github account

  • Copy the SSH Key, remember that do not add any whitespace or newlines
<?$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • Clicking to your account and selecting Setting. You will see SSH and GPG keys, then click to Add New SSH Key.
  • You click Paste the SSH Key that you copied and confirm your Github password after adding your SSH Keys Pair.
How-to-Generate-SSH-for-Specific-Projects-say-Github?

#2. Testing your SSH Keys Pair

  • Open Git Bash and enter the command:
<?$ ssh -T git@github.com
# Attempts to ssh to GitHub
  • You will see the message like this:
<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)?

or:

<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?
  • Then, type YES to see whether your SSH Key on Github works or not. If it runs successfully, you will see this display:
<?> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

#3. Working with SSH Key Passphrases

Someone can access your system if they can access your computer. To ensure more security for your account and website, you can use ssh-agent to save your password, therefore, you do not have to re-enter it.

You can change your password without re-entering the key through the command below:

<?$ ssh-keygen -p
# Start the SSH key creation process
> Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter]
> Key has comment '/Users/you/.ssh/id_rsa'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [One more time for luck]
> Your identification has been saved with the new passphrase.

But if you install your SSH Keys Pair on the Windows, instead of following the command above; you can copy the code below into your Git Shell:

<?env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi 
unset env

Therefore, when you run your Git Bash, you will be required to enter your password:

<?> Initializing new SSH agent...
> succeeded
> Enter passphrase for /c/Users/you/.ssh/id_rsa:
> Identity added: /c/Users/you/.ssh/id_rsa (/c/Users/you/.ssh/id_rsa)
> Welcome to Git (version 1.6.0.2-preview20080923)
>
> Run 'git help git' to display the help index.
> Run 'git help ' to display help for specific commands.

[BONUS] Share Access To Magento Commerce Cloud And GitHub Branches

In Magento 2, you can add SSH Keys to Share access to Magento Commerce Cloud or Share access to GitHub branches.

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

 

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

<?ssh-add ~/.ssh/id_rsa

But if you do not have, you can follow some simple steps we present below.

First, enter the email you registered your Github account:

<?ssh-keygen -t rsa

When it displays “Enter a file in which to save the key,”, you click Enter to save your default location to save your Magento 2 SSH Key.

Next, after creating the SSH Keys pair, you will start with ssh-agent:

For Mac and Linux:

<?eval "$(ssh-agent -s)"

For Windows:

<?eval $(ssh-agent -s)

Then, add your Magento 2 SSH Key,

For Mac:

<?ssh-add -K ~/.ssh/id_rsa

For Windows and Linux:

<?ssh-add ~/.ssh/id_rsa

Test the Magento 2 SSH Key

After adding the Magento 2 Authentication SSH Key for GitHub, make sure to test your keys pair whether it works or not. Firstly, enter the following command:

<?ssh -T git@github.com

Then, click YES when seeing the warning box, displaying it on the screen. You will receive the success message if it works.

If you receive the message error, you can check with some explanations below:

  • Do you connect to the right server? Make sure your connection is right by following the command:
<?$ ssh -vT git@github.com
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Reading configuration data /Users/you/.ssh/config
> debug1: Reading configuration data /etc/ssh_config
> debug1: Applying options for *
> debug1: Connecting to github.com [IP ADDRESS] port 22.
  • You have to use “Git user” instead of using “Github” username. You also verify your connection by the command:
<?$ ssh -T git@github.com
> Hi username! You've successfully authenticated...
  • Check your key by connecting to You can also check that the key is being used by trying to connect to git@github.com:
<?$ ssh -vT git@github.com
> ...
>> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

How To Add a Public SSH Key To The Magento Account?

#1. Using the CLI to add SSH Key

  • Open to your default location you stored your Magento 2 Authentication SSH Key for Git, and log in to your project and add the key:
<?Magento-cloud 
ssh-key:add ~/.ssh/id_rsa.pub
  • In your account, you have to choose and add your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?
  • Copy your SSH Public Key and Login and access the Project Web Interface account.
  • Install your SSH Key in the selected branch.
  • Copy and Paste your SSH Public Key.
How-To-Add-a-Public-SSH-Key-To-The-Magento-Account?

#2. Using Magento Cloud CLI to add SSH key

First, you log into the project and list your project IDs:

<?magento-cloud login
>magento-cloud project:list

Then, list SSH into the environments in the project:

<?magento-cloud environment:list -p <project ID>
magento-cloud ssh -p <project ID> -e <environment ID>

#3. Pro Staging and Production SSH Key command

You can add SSH Key in the Pro Staging and Production and use Linux command to manage the system.

Production:

<?ssh <project ID>@<project ID>.ent.magento.cloud

Staging:

<?ssh <project ID>_stg@<project ID>.ent.magento.cloud

How to Generate SSH for Specific Projects, say Github?

#1. Adding a new SSH key to your Github account

  • Copy the SSH Key, remember that do not add any whitespace or newlines
<?$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • Clicking to your account and selecting Setting. You will see SSH and GPG keys, then click to Add New SSH Key.
  • You click Paste the SSH Key that you copied and confirm your Github password after adding your SSH Keys Pair.
How-to-Generate-SSH-for-Specific-Projects-say-Github?

#2. Testing your SSH Keys Pair

  • Open Git Bash and enter the command:
<?$ ssh -T git@github.com
# Attempts to ssh to GitHub
  • You will see the message like this:
<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)?

or:

<?> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?
  • Then, type YES to see whether your SSH Key on Github works or not. If it runs successfully, you will see this display:
<?> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

#3. Working with SSH Key Passphrases

Someone can access your system if they can access your computer. To ensure more security for your account and website, you can use ssh-agent to save your password, therefore, you do not have to re-enter it.

You can change your password without re-entering the key through the command below:

<?$ ssh-keygen -p
# Start the SSH key creation process
> Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter]
> Key has comment '/Users/you/.ssh/id_rsa'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [One more time for luck]
> Your identification has been saved with the new passphrase.

But if you install your SSH Keys Pair on the Windows, instead of following the command above; you can copy the code below into your Git Shell:

<?env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi 
unset env

Therefore, when you run your Git Bash, you will be required to enter your password:

<?> Initializing new SSH agent...
> succeeded
> Enter passphrase for /c/Users/you/.ssh/id_rsa:
> Identity added: /c/Users/you/.ssh/id_rsa (/c/Users/you/.ssh/id_rsa)
> Welcome to Git (version 1.6.0.2-preview20080923)
>
> Run 'git help git' to display the help index.
> Run 'git help ' to display help for specific commands.

[BONUS] Share Access To Magento Commerce Cloud And GitHub Branches

In Magento 2, you can add SSH Keys to Share access to Magento Commerce Cloud or Share access to GitHub branches.

The SSH keys allow managing branches and pushing code without having to constantly supply your username and password. You can add multiple SSH keys to GitHub per workspace you use.

Share access to Magento Commerce Cloud

As the admin of the account, you have a right to give permission to share your Magento account to your trusted employees to help you manage the online business site.

When your account is shared, all the databases, for example, card and customers’ information still remains to protect. It will not share with the other users.

To set up the Magento sharing account

  • Log in to your Magento account > Choose Shared Account in the left panel > Add a new user.
Share-access-to-Magento-Commerce-Cloud
  • Enter the ID, Email, and the name of a shared account.
  • Enter your email and your phone, then, click Create Shared Access.
Share-access-to-Magento-Commerce-Cloud

To access a shared account

  • You can click Switch Accounts in the upper-right corner of My Account to switch to the shared account.
Share-access-to-Magento-Commerce-Cloud

Share access to GitHub branches

You can limit the user so that only certain managers, users you trust to access your account to protect your customers’ information and organization.

  • On your Github account, click Setting > Branches on the left. You can set your own rules and branch name you want to protect.
Share-access-to-GitHub-branches
  • Then, you select Restrict who can push to matching branches and enter the name of teams and people you trust to push the protected branch.
Share-access-to-GitHub-branches

Wrapping Up

Once you add Magento 2 SSH Key to your online store, your site will be more secure, supporting you to protect clients’ information and your store.

If you need any help, feel free to contact us. We’re 24/7 support you.

Or you can check our website to learn more about Magento.

Read more:

Leave a Reply

Your email address will not be published. Required fields are marked *