Posts Tagged Linux

Using standard command “go get” for private golang packages on gitlab.com

I’m keeping my projects privately on gitlab.com and want to use for some of my golang packages standard “go get” command instead of using git clone/pull. When I’m trying to use standard commands I’m getting the error

go get gitlab.com/bykovme/my_package_here
# cd .; git clone https://gitlab.com/bykovme/my_package_here.git /home/bykov/gopath/src/gitlab.com/bykovme/my_package_here
Cloning into '/home/bykov/gopath/src/gitlab.com/bykovme/my_package_here'...
fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled

As I’m using SSH keys to access the git repository, the following command solves the issue giving possibility to use standard go packages commands

git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/"

You can check if it was applied using the following command

cat ~/.gitconfig

The output of the command above should be like the text below

[url "git@gitlab.com:"]
    insteadOf = https://gitlab.com/

The command

go get gitlab.com/bykovme/my_package_here

is working now.

PS. The same solution is working for github.com

, , , , , , , ,

Leave a comment

Login with SSH without password (Mac, Linux)

1. Go to computer where you want to connect from. Check the folder $HOME/.ssh/, if there is a file id_rsa.pub then skip this step. Otherwise generate generate new rsa keys using the following command:

ssh-keygen -t rsa

2. Go to computer where you want to connect with ssh to. Check the folder $HOME/.ssh/, if it exists then skip this step otherwise create new one with the command:

mkdir -p .ssh

3. Go back to computer where you want to connect from and use the command below to copy public key, it will ask your password for the last one time:

cat ~/.ssh/id_rsa.pub | ssh user_on_remote_computer@remote_computer_host  'cat >> ~/.ssh/authorized_keys'

4. We are ready! Connect without entering password:

ssh user_on_remote_computer@remote_computer_host

Enjoy!

,

Leave a comment

Starting command line program/script in background as job (Linux, Mac)

It is important to  use the command “nohup” and also redirect everything, otherwise the job will be killed after leaving console

nohup ./your_program_or_script_here > copyout.log 2> copyout.err < /dev/null &

On the other side, if you need just to run something in background because you are afraid that you will loose the session, the best way for it is using tmux, it can be installed with “apt-get install tmux” in Ubuntu Linux or “brew install tmux” on Mac

Open new session:

tmux new -s session_name

Attach to the lost session:

tmux attach -t session_name

, , , , ,

Leave a comment

Change default console editor in Linux

I do not like default console editors in Linux, if you have the same issue and want to use another editor in your terminal by default, use the following command:

update-alternatives –config editor

This command will show you alternative editors as below, select the one you like more ( I personally like mcedit, it comes together with midnight commander) 🙂

There are 5 choices for the alternative editor (providing /usr/bin/editor).

 Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
 1 /bin/ed -100 manual mode
 2 /bin/nano 40 manual mode
 3 /usr/bin/mcedit 25 manual mode
 4 /usr/bin/vim.basic 30 manual mode
 5 /usr/bin/vim.tiny 10 manual mode
Press enter to keep the current choice[*], or type selection number: 3

, , , , , ,

1 Comment

MD5 in Linux command line

Getting MD5 sum from the string in Linux command line:

echo -n “Welcome” | md5sum

Leave a comment

Disk usage in command line for Linux & Mac

Quick way to get disk usage for current folder in command line for Linux:

du * -h –max-depth=0 | sort -h

For Mac:

du -hm -d 1 | sort -n

Free disk space can be checked in both systems the same way:

df -h

 

, , , ,

Leave a comment