Automate Login in Shell Script - macos

I want to create an automate login for github push to repository script in mac terminal. But I met some problem with login issue, like it will ask for username and password, so what command that can automatically insert username when it ask for username same with password?
I found 'expect' command in Linux, but the way of using is different in Mac terminal.
Lunayos-MacBook-Pro:SuperDeals-iPhone Lunayo$ git push origin
Everything up-to-date
Lunayos-MacBook-Pro:SuperDeals-iPhone Lunayo$ git push upstream
Username:

You should refer to GitHub's excellent help articles:
Set Up Git
SSH key passphrases
Remotes
You need to either generate an SSH key with no passphrase (or start ssh-agent before you use your script if you would like to use a passphrase); otherwise, OpenSSH will ask for a password or passphrase.
Also ensure that your remote URL looks like ssh://git#github.com/user/repo.git or git#github.com:user/repo.git. Specifically, the git# part tells Git and OpenSSH that you want to make the SSH connection using the username git (which is correct for all GitHub repositories).

Related

github ssh key names

I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).
I had previously been using password-based authentication, which is repetitive to keep typing in my passwords. I followed the steps (using windows) to set up SSH keys in github. I gave my key a specific name, anticipating that I will need more than one SSH key at some point. It doesn't make sense to always have id_rsa for github! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key. But running a git clone gave me this error:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I then had the idea to try it with the default name (id_rsa), rather than my custom name, and of course it works. So my question is how do I avoid this? I don't want the default name to be reserved for github.
You can set up an ssh configuration file to tell the ssh command to use that specific key when connecting to github.
Create the file .ssh/config with the content:
Host github.com
IdentityFile ~/.ssh/github_rsa_key
Assuming that you've named your private key ~/.ssh/github_rsa_key.
Now try connecting to github:
$ ssh git#github.com
You should see:
Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.

how can I make git clone fail on password prompt

I am git cloning ~3000 repositories in a bash script like this:
[loop-sy]
git clone https://foobar.com
[ys-pool]
Most of these are public repositories and it works fine, but some of them are private and they return a username and password challenge. Is there a way to just move to the next repo (i.e. fail and get on with it) rather than having the bash script stop for me to enter the username and password.
I have searched high and low, but I have not found an answer yet.
I am running an Ubuntu 18.04 server and have root privileges.
You can set GIT_TERMINAL_PROMPT to 0, which will prevent Git from prompting for credentials. It will still use any that it can find in any credential helper you may be using, but if those don't work, it will just fail instead of prompting.

Switching my git bash credentials from virtual machine to my home system

I am about to finish a coding boot camp which had us blindly set up our git and github account info through Vagrant/putty in the beginning using SSH keys. I went ahead and downloaded cmder and set it up to launch bash on terminal open, but when I try to git push or pull, I am getting an error Permission denied(publickey). fatal: could not read from remote repository.
I have checked the username and email, and they are set to my correct credentials. Will the fact that I made the SSH keys while logged in to the schools Vagrant system cause issues, and if so, is there a way to strip and reset my SSH keys or switch my git to use HTTPS credentials to log in?
I've done a good bit of googling and only come across ways to install and setup git bash, which I've of course already done. Thanks in advance for any help.
One benefit of using SSH keys over your username and password is that you can have separate keys for each machine you'll log into GitHub with. Don't transfer the keys; just generate new ones for your home machine, and disable the old VM keys on GitHub's end.

Can't log in to Github for Mac client after changing my computer's name

I changed my computer's name, and now I cannot log into the Github for Mac client. When I try to log in through the "preferences" section in Github for Mac, I get a "Login or password is incorrect" message. I am certain that they are in fact, correct.
I figured this had something to do with my SSH key being tied to my computer name, so I generated a new SSH key.
After changing my SSH key, and adding it through github.com, I ran:
ssh -T git#github.com
I get the success message:
Hi alexweissman! You've successfully authenticated, but GitHub does not provide shell access.
I also did
git config --global user.email <my-email-address>
Which seemed to work without any complaint.
Strangely, when I attempt to sync a commit, and it prompts me for my username and password, it accepts it without any complaint. I suspect that Github for Mac has cached my old SSH key somewhere and is somehow trying to use that in conjunction with the "remember me" feature.
I am running OSX 10.8.5.
Try this:
Go to https://github.com/settings/applications and revoke the access to GitHub For Mac. Then try the login

Unable to clone git repository from siteground

I'm trying to set up MS WebMatrix to use a Git repository from my siteground hosting account. I created the repository using their cpanel plugin and it tells me that I can clone it using this command
git clone ssh://username#sm3.siteground.biz:18765/home/username/public_html/
I replaced username of course and I created an rsa key using ssh-keygen. In the Webmatrix GUI it just opens a window saying "Clone is in progress" but it doesn't to anything.
And when I run that command in PowerShell, this is the output:
Cloning into 'public_html'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any help is highly appreciated!
EDIT:
I haven't used github before but I'm pretty sure I'm not connecting to it. The repository is on siteground's server I think. Anyway, I couldn't figure it out in PowerShell so now I'm using putty to load the appropriate key and connect using an external git tool (source tree) that doesn't use the same ssh client as PowerShell. That is the solution that's working for me now.
I'll leave this question open as maybe someone comes around and can help with how to set this up using PowerShell.
The missing piece to the Siteground guide is:
Create a blank file in ~/.ssh/ or C:\Users\username\.ssh on your computer. It does not matter what you name it. I named it siteground_dsa. You could also name it id_dsa_siteground.
Copy the private ssh key that you get from siteground.com and paste the whole of it in the this newly created file.
Open Git Bash locally on your computer and run the following command
$ eval ssh-agent -s
Then run the following. Remember to use the filename that you gave it.
$ ssh-add ~/.ssh/siteground_dsa
Now you need to enter the passphrase for the ssh key. You will have defined it when creating the ssh key.
Now you should be logged in and you can run git clone the directory of your wish.
git clone ssh://username#ams14.siteground.eu:18765/home/username/public_html/
To permanently add the SSH key extend ~/.ssh/config with the following and updating server_name and username.
Host server_name
User username
Port 18765
IdentityFile ~/.ssh/siteground_dsa
keep in mind that for Windows operators, you should write eval $(ssh-agent)
eval $(ssh-agent)
chmod 600 file_name
ssh-add C:\Users\username\.ssh\siteground
Then you can easily clone your file into your local server following inserting your passphrase of the SSH key.
GitHub isn't able to authenticate you. Probably your key isn't associated with your GitHub account.
Take a look to GitHub's recommended method

Resources