Linux HowTo: Setting an alias in an ssh session without using bashrc/profile

Original Source Link

How can I set an alias on a remote machine over SSH with local ssh config (not editing the remote bashrc/profile files).

Background: I have a remote dev build machine that is shared with a few devs. We only use it for building software and publishing it, but occasionally, we need to make small changes in the code and git commit those. I don’t want ssh keys on the remote machine, so we are using SSH agent forwarding so our local SSH keys are available on the remote machine for git push. But we still need to set the git user.name and user.email on the remote machine. Currently, just after logging in, I execute alias git='git -c "user.name=My Name" -c "[email protected]"' so the git commits are attributed to me. Since we share the same account with a few devs, I don’t want to set that alias in the remote ~/.bashrc file. So is there a way to set that command in my local ~/.ssh/config for the host so it gets executed in the shell when I login?

Ok, from a bunch of different questions I did manage to piece a solution together.
First of all, you can use RemoteCommand and LocalCommand in your ~/.ssh/config file to execute a local command before logging in, and then instead of just dropping to a shell, execute a different command (shell). I couldn’t make it work with only RemoteCommand (there is no way it seems to execute a remote command that includes setting an alias), but what you can do is provide a different .bashrc file.

So it works like this: copy a local .bashrc file to the remote machine under a different name in /tmp. Login, execute bash and specify the .bashrc file, and at logout, remove it again. Also, when you use RemoteCommand in ~/.ssh/config you need to tell ssh to force a pseudo-tty so you get a normal interactive shell.

This is my relevant section in ~/.ssh/config:

Host mymachine
    Hostname mymachine.mydomain.com
    ForwardAgent yes
    User someuser
    RequestTTY force
    PermitLocalCommand yes
    LocalCommand scp ~/.sshrc [email protected]:/tmp/.bashrc_someuser
    RemoteCommand bash --rcfile /tmp/.bashrc_someuser; rm /tmp/.bashrc_someuser

The ~/.sshrc filename is arbitrary. It’s just a file anywhere on your local machine. you can even make multiple versions for different remote ssh machines.

This is what my ~/.sshrc file looks like:

source ~/.bashrc
alias git='git -c "user.name=Me" -c "[email protected]"'

This will ensure the .bashrc of the remote machine is applied, but then you can add your own customizations afterwards. Now I just ssh there with ssh mymachine and the git command works and uses whatever keys I have available in my local machine.

Tagged : / / /

Making Game: Setting an alias in an ssh session without using bashrc/profile

Original Source Link

How can I set an alias on a remote machine over SSH with local ssh config (not editing the remote bashrc/profile files).

Background: I have a remote dev build machine that is shared with a few devs. We only use it for building software and publishing it, but occasionally, we need to make small changes in the code and git commit those. I don’t want ssh keys on the remote machine, so we are using SSH agent forwarding so our local SSH keys are available on the remote machine for git push. But we still need to set the git user.name and user.email on the remote machine. Currently, just after logging in, I execute alias git='git -c "user.name=My Name" -c "[email protected]"' so the git commits are attributed to me. Since we share the same account with a few devs, I don’t want to set that alias in the remote ~/.bashrc file. So is there a way to set that command in my local ~/.ssh/config for the host so it gets executed in the shell when I login?

Ok, from a bunch of different questions I did manage to piece a solution together.
First of all, you can use RemoteCommand and LocalCommand in your ~/.ssh/config file to execute a local command before logging in, and then instead of just dropping to a shell, execute a different command (shell). I couldn’t make it work with only RemoteCommand (there is no way it seems to execute a remote command that includes setting an alias), but what you can do is provide a different .bashrc file.

So it works like this: copy a local .bashrc file to the remote machine under a different name in /tmp. Login, execute bash and specify the .bashrc file, and at logout, remove it again. Also, when you use RemoteCommand in ~/.ssh/config you need to tell ssh to force a pseudo-tty so you get a normal interactive shell.

This is my relevant section in ~/.ssh/config:

Host mymachine
    Hostname mymachine.mydomain.com
    ForwardAgent yes
    User someuser
    RequestTTY force
    PermitLocalCommand yes
    LocalCommand scp ~/.sshrc [email protected]:/tmp/.bashrc_someuser
    RemoteCommand bash --rcfile /tmp/.bashrc_someuser; rm /tmp/.bashrc_someuser

The ~/.sshrc filename is arbitrary. It’s just a file anywhere on your local machine. you can even make multiple versions for different remote ssh machines.

This is what my ~/.sshrc file looks like:

source ~/.bashrc
alias git='git -c "user.name=Me" -c "[email protected]"'

This will ensure the .bashrc of the remote machine is applied, but then you can add your own customizations afterwards. Now I just ssh there with ssh mymachine and the git command works and uses whatever keys I have available in my local machine.

Tagged : / / /

Server Bug Fix: How to prevent node js from serving .git folders and all the files under .git

Original Source Link

I know that using .htaccess file can restrict files to be served under .git but how do i acheive the same if i’m using node.js server. I use forever to start/stop the servers.

If you are using Express, the answer is here: https://stackoverflow.com/a/11911629

You did not provide enough information on your setup to give a more detailed answer.

Tagged : / /

Ubuntu HowTo: fatal: unable to access “…”: gnutls_handshake() failed: Handshake failed

Original Source Link

I’ve been using Git for the past few months. Recently when I try to clone or to push, I keep on getting this error. I’ve researched on the internet but so far no solution has worked for me. Does anyone have an idea?

External note : Now I moved to different country, it was working perfectly where I was before. Git Version : 2.11.0 , OS : Debian GNU/Linux 9.11 (stretch)

Error :
git push or git clone
fatal: unable to access ‘https://**************/’: gnutls_handshake() failed: Handshake failed

I get “gnutls_handshake() failed” message as well.
You could try to compile git with OpenSSL instead of gnutls using Paul N. Baker’s shell script.

This shell script works for me.

Tagged : / / /

Code Bug Fix: ” is not recognized as an internal or external command, operable program or batch file. when issuing a git rev-list

Original Source Link

Whenever I try to run this command in windows terminal. I get a

” is not recognized as an internal or external command,
operable program or batch file.

git rev-list --all --objects | 
    sed -n $(git rev-list --objects --all | 
    cut -f1 -d' ' | 
    git cat-file --batch-check | 
    grep blob | 
    sort -n -k 3 | 
    tail -n40 | 
    while read hash type size; do 
         echo -n "-e s/$hash/$size/p ";
    done) | 
    sort -n -k1

These commands are intended to be given to a POSIX shell, not the Windows command prompt.

The way you have pasted the instructions into the command prompt, the character is interpreted as a command. Neither does such a command exist nor is the character intended to be interpreted as a command (it is actually used to tell the POSIX shell that the command continues on the next line).

Tagged : / /

Code Bug Fix: Migrate TFS repo to AzureDevOps repo – missing files from solution

Original Source Link

I have a BI solution with SSAS, SSIS, SSRS and .sqlproj projects stored in a TFS – git repo. I have migrated it from TFS – git repo into a AzureDevOps repo using the Visual Studio 2019 as an intermediary tool.
Cloned the solution from the TFS repo on my local machine and then push all the files (entire solution) to the AzureDevOps repo, but it seems that not all the files were push into the new repo.

Is there a maximum limit of pushing files using VS 2019?
My solution has a total number of 2.601 files and the size on disk is only 143 MB …

No need to use Visual Studio 2019 as an intermediary tool.

Directly use git command line to handle this in case some files auto ignored by visual studio.

As Etienne commented, also pay attention to your .gitignore file, make sure all files you need are committed and pushed to remote Azure DevOps Repo.

You could refer this blog to manually migrate the Git repo in five easy steps:

  • Create an empty Git repo
  • Mirror the repository
  • Push the repo
  • Validate the new repository
  • Configure the new repo
Tagged : / / / /

Linux HowTo: Gitlab and Rsync updates servers files incorrectly

Original Source Link

I don’t know how necessarily say this correctly, as I simply am not sure what is happening.

I’ve got a website that is being updated using gitlab ci. When attempting to push new code today I received an error. It was terribly non-descriptive and related to the site itself. It was a Drupal site and I was trying to install a custom module.

The module CustomModule cannot be installed because it's missing a dependency module

It provided a fully blank file name for a module.

After digging I managed to find the problem. Somehow, the server has received files from two different points in commit history. I had not previously pushed this branch to the server. On the server some files were from the latest commit and others were from what looked like the first commit from that branch.

This sounds really wacky and I agree. I noticed that the site was telling me my module that I was pushing was missing a dependency, when I looked at what it was missing it listed a dependency that I had NOT listed (it was entirely wrong, no question).

After looking at the new files I realised, some were from an earlier commit. It wasn’t just grabbing an earlier version of all files because some files were from the latest commit. I checked the jobs and it listed all the files in the call to rsync.

The rsync call looks like :
rsync -av --no-perms --no-owner --no-group --exclude-from '.gitlabci-rsync-exclude.txt' --exclude '.git' --delete ./ $RSYNC_DESTINATION

What makes this even stranger is that minutes before this happened, the exact same job ran to merge some updates and that went off without a hitch. Then this one made the jobs fail.

I don’t know what more info I can give as I am not terribly sure what is happening. Any ideas or more info you would need?

Rsync may have some weird side effects .

You will probably have some more luck by creating (and archiving) tar files, then transferring those versioned files, then untar them.

In your .ci file, tar and archive an date/time/commit-id tar with the same exclusions, then rsync it.

Tagged : / /

Making Game: Gitlab and Rsync updates servers files incorrectly

Original Source Link

I don’t know how necessarily say this correctly, as I simply am not sure what is happening.

I’ve got a website that is being updated using gitlab ci. When attempting to push new code today I received an error. It was terribly non-descriptive and related to the site itself. It was a Drupal site and I was trying to install a custom module.

The module CustomModule cannot be installed because it's missing a dependency module

It provided a fully blank file name for a module.

After digging I managed to find the problem. Somehow, the server has received files from two different points in commit history. I had not previously pushed this branch to the server. On the server some files were from the latest commit and others were from what looked like the first commit from that branch.

This sounds really wacky and I agree. I noticed that the site was telling me my module that I was pushing was missing a dependency, when I looked at what it was missing it listed a dependency that I had NOT listed (it was entirely wrong, no question).

After looking at the new files I realised, some were from an earlier commit. It wasn’t just grabbing an earlier version of all files because some files were from the latest commit. I checked the jobs and it listed all the files in the call to rsync.

The rsync call looks like :
rsync -av --no-perms --no-owner --no-group --exclude-from '.gitlabci-rsync-exclude.txt' --exclude '.git' --delete ./ $RSYNC_DESTINATION

What makes this even stranger is that minutes before this happened, the exact same job ran to merge some updates and that went off without a hitch. Then this one made the jobs fail.

I don’t know what more info I can give as I am not terribly sure what is happening. Any ideas or more info you would need?

Rsync may have some weird side effects .

You will probably have some more luck by creating (and archiving) tar files, then transferring those versioned files, then untar them.

In your .ci file, tar and archive an date/time/commit-id tar with the same exclusions, then rsync it.

Tagged : / /

Ubuntu HowTo: GitHub account setup in Ubuntu 20.04

Original Source Link

How do i set up my GitHub account in my Ubuntu machine?

Via Command Line, I have configured the email & username variables, when doing the git push for the first time & I entered my account credentials when prompted. But it throws the error remote: Invalid username or password.

I have enabled Two-factor authentication (2FA) in my account & when i tried with similar approach via Git CMD in Windows, an UI window popped up to enter & verify the 2FA .

How it should be achieved in Ubuntu ?

Ubuntu OS version: 20.04
GitHub Version: 2.25.1

Tagged : / / /

Code Bug Fix: Git auto-merging removed some information while cherry-picking

Original Source Link

At work, I had to include a commit from a remote branch to my local branch.

Because I did not want to merge yet, I cherry-picked the remote commit to my local branch.

While cherry-picking, Git performed an auto-merge whithout prompting me for a conflict.

I then realized that some vital lines of code from the remote were missing from the resulting commit.

I put the case here:

https://github.com/apicoding/SimplePrj

1. My ‘Initial commit’ in master is missing the mandatory ‘Print()’ method implementation.

2. The ‘Print()’ method is defined in ‘Ready to merge’ commit in remote.

3. After cherry-picking/auto-merge ‘Ready to merge’ commit to master,
the ‘Print()’ method is still undefined.

Do you have an explanation why git cherry-pick can choose to remove some information whitout raising a conflict and asking the user to choose ?

When you’re cherrypicking, you’re taking the commit you cherrypick into your branch, so if you cherrypicked the Ready to merge commit from remote then only the comment //ready to merge went to your branch (which is the only change that commit has).

If you wanted to take all the changes from remote you should’ve merged the branch, not cherrypicked that single commit.

Hope it helps!

Tagged : / /