Fix for “ssh-add: Could not open a connection to your authentication agent.”

You might have tried adding a key with:

ssh-add .ssh/id_rsa

only to get this error:

ssh-add .ssh/id_rsa
Could not open a connection to your authentication agent.[/code]
If this happens, it is because your ssh agent is not running in the terminal.

Run this:
exec ssh-agent bash

which will cause it to resource your .bashrc files and start the agent.

Now try readding the key again:

ssh-add .ssh/id_rsa
Identity added: .ssh/id_rsa (.ssh/id_rsa)

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Compile and install mc in a non root Linux environment (XDA and Goo.im)-WIP

Get the source:

mkdir ~/sources && cd ~/sources

wget http://ftp.gnu.org/gnu/mc/mc-4.6.1.tar.gz

tar -xvvf mc-4.6.1.tar.gz
cd ~/sources/mc-4.6.1
./configure –prefix=/home/droidzone/myapps

Error:
checking for pkg-config… no
*** The pkg-config script could not be found. Make sure it is
*** in your path, or set the PKG_CONFIG environment variable
*** to the full path to pkg-config.
*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config.
checking for glib-config… no
checking for glib12-config… no
checking for glib-config… no
checking for GLIB – version >= 1.2.6… no
*** The glib-config script installed by GLIB could not be found
*** If GLIB was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the GLIB_CONFIG environment variable to the
*** full path to glib-config.
configure: error: Test for glib failed.
GNU Midnight Commander requires glib 1.2.6 or above.

So install pkg-config:
cd ~/sources
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.27.1.tar.gz
tar -xvvf pkg-config-0.27.1.tar.gz
cd pkg-config-0.27.1/
./configure –prefix=/home/droidzone/myapps –with-internal-glib
make && make install

Confirm that it works:
[email protected]:~/sources/pkg-config-0.27.1$ which pkg-config
/home/droidzone/myapps/bin/pkg-config

Now retry installing mc:
cd ~/sources/mc-4.6.1
./configure –prefix=/home/droidzone/myapps

Error:
checking for pkg-config… /home/droidzone/myapps/bin/pkg-config
checking for glib-2.0… checking for glib-config… no
checking for glib12-config… no
checking for glib-config… no
checking for GLIB – version >= 1.2.6… no
*** The glib-config script installed by GLIB could not be found
*** If GLIB was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the GLIB_CONFIG environment variable to the
*** full path to glib-config.
configure: error: Test for glib failed.
GNU Midnight Commander requires glib 1.2.6 or above.

Ok, install glib now:
cd ~/sources
wget http://ftp.acc.umu.se/pub/GNOME/sources/glib/2.34/glib-2.34.0.tar.xz
tar -Jxvvf glib-2.34.0.tar.xz
cd glib-2.34.0/
./configure –prefix=/home/droidzone/myapps

Error:
checking for inflate in -lz… no
configure: error: *** Working zlib library and headers not found ***

cd ~/sources
wget http://zlib.net/zlib-1.2.7.tar.gz
tar -xvvf zlib-1.2.7.tar.gz
cd zlib-1.2.7/
./configure –prefix=/home/droidzone/myapps
make && make install

Now retried glib installation, to be met with another error:
checking for LIBFFI… no
configure: error: Package requirements (libffi >= 3.0.0) were not met:

No package ‘libffi’ found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBFFI_CFLAGS
and LIBFFI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

wget ftp://sourceware.org/pub/libffi/libffi-3.0.11.tar.gz
tar -xvvf
cd libffi-3.0.11
./configure –prefix=/home/droidzone/myapps
make && make install
———————————————————————-
Libraries have been installed in:
/home/droidzone/myapps/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,-rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/ld.so.conf’

export LD_LIBRARY_PATH=/home/droidzone/myapps/lib

Rerying glib config:
checking for msgfmt… no
configure: error:
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html

Gettext make led to errors:
/home/droidzone/myapps/lib/libncurses.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[4]: *** [libgettextlib.la] Error 1
make[4]: Leaving directory `/home/droidzone/sources/gettext-0.18.1.1/gettext-tools/gnulib-lib’
make[3]: *** [all] Error 2
make[3]: Leaving directory `/home/droidzone/sources/gettext-0.18.1.1/gettext-tools/gnulib-lib’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/droidzone/sources/gettext-0.18.1.1/gettext-tools’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/droidzone/sources/gettext-0.18.1.1/gettext-tools’
make: *** [all-recursive] Error 1
[email protected]:~/sources/gettext-0.18.1.1$


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Making your ssh life paradise – Using a config file

The config file can automate many tedious processes.

Eg: You wish to scp a file from the current machine to a host like XDA, using a specific identity key. Of course you can use ssh-add to add the key, but it may not be recognized each reboot.

The usual command is like

scp -i ~/.ssh/path_to_keyfile sourcefilename [email protected]:~/targetpath

Once a .config file is set up, your new command becomes:

scp sourcefile xda:target

Really!

Create a text file in ~/.ssh/config:

[email protected]:~$ cat /home/droidzone/.ssh/config                                                                                                                    
Host bitbucket                                                                                                                                               
    IdentityFile ~/.ssh/bitbucket                                                                                                                                     
Host xda                                                                                                                                                              
     HostName build1.dev.xda-developers.com                                                                                                                           
     User droidzone                                                                                                                                                   
     IdentityFile ~/.ssh/xdamachine_key_openssh_pvt                                                                                                                   
     ServerAliveInterval 30                                                                                                                                           
     ServerAliveCountMax [email protected]:~$

Here, as you can see, I’ve added two hosts. One is my Bitbucket account, and I’ve specified a key file for authentication.

For XDA, I’ve given it a label “xda”, specified the build server username and hostname, specified an identity file, and a timeout interval.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

SSH into a server with an alternate key

When you have more than one private key, you need to specify the add the alternate key for authentication. The preferred method is to do a:

ssh-add ~/.ssh/alternate_private_keyfile

 

However in certain cases, you may need to do this for each session. Or there may be cases where you dont have access permissions to execute this file on the server.  In such cases, you can directly add the key to the agent by adding the paramters for the key to a file ~/.ssh/config. Create this file if it doesnt exist.

emacs ~/.ssh/config

 

In the file, add the following line and modify it as per the key file path for your private key:

IdentityFile ~/.ssh/id_dsa_xda
IdentityFile ~/.ssh/sourceforge_droidzonedroidzone

Here, two keys are being added to the client.

The third way is to specify the keyfile with the ‘-i ‘ option while sshing or doing an scp. Tedious, and can be overcome by the method described above.

Note that after copying any key into .ssh/, you have to disable read/write access to the group and others by:

chmod 600 ~/.ssh/keyfile

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Pushing a file via ftp and the bash command line to an ftp server

Since I work with the XDA server, I often have to work on stuff in the XDA server, finish it and upload it to my host. Now Goo.im conveniently offers a sftp access, that makes everything very easy. A simple scp command can transfer the file (already descibed elsewhere on my blog). However when it comes to transferring the files via simple ftp, things are a bit different. You need a bash scrip to do it.

I’ve used this script from  Ubuntuforums to suit my needs perfectly:

# The next 9 lines are lifted from mickwombat's script
#!/bin/sh
USERNAME="[email protected]"
PASSWORD="myftppassword"
SERVER="ftp.droidzone.in"
# Directory where file is located
DIR=$2
#  Filename of backup file to be transfered
FILE=$1
# login to ftp server and transfer file

curl -T $FILE -u $USERNAME:$PASSWORD $SERVER/$DIR/

This very neatly takes the file specified in the first argument, and transfers it to ftp.droidzone.in/dir where dir is the specified directory.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Using the XDA Build server (Transferring files from a remote server with scp)

XDA’s Build server for Recognized developers, in the works, does not have a public access section for the file system where files may be uploaded and may be downloaded. That may probably change in the future, as this is a beta thing kept under wraps, and open for only RDs.

For now, if you wish to transfer files from the server, you may use the scp service, either with a frontend like Filezilla, or from the command line. This is important for me because I’d like to remote upload my compiled files from the XDA build server to Goo.im, or Sourceforge and offer it to my users for download.

So on the second remote server (like Goo or Sourceforge) where you have ssh access, follow the following steps:

Login with ssh in the usual way with Putty or ssh to the second server (Goo or Sourceforge, will be called server2) where you have a public section of the file system (public_html or www).

Create a remote key on this server (server2), with:

ssh-keygen -t rsa

Now, you have to transfer the public key for this server2 to the server1. In other words, you are going to remote access server1 from server2. So you have to have a public/private key pair on server2, and transfer its public key to server1.

Once the key pair is set up, transfer the public key to server1. If server1 already has other keys setup, edit ~/.ssh/authorized_keys in a text editor (I prefer emacs), and add the new public key to the last line, and press enter (for a newline char). Save authorized_keys.

Now server1 will accept remote connections from server2.

Transfer from Remote to Local (Or two remotes, if one of them is logged into)

Now, use the following scp command to transfer the file remotely from the XDA filesystem, to the currently logged in server:

scp -i .ssh/goo_xda [email protected]:pathtofile targetonhost2

 

Eg:

 

scp -i .ssh/goo_xda [email protected]:~/myfiles/compiled.tar.bz2 ./myfolder/

 

This will use a ssh key at .ssh/goo_xda (Private key on the logged in server-Server2), to login to server 1 (devserver.xda.com) with username dz, and copy a file at ~/myfiles/compiled.tar.bz2 from server1 to  ./myfolder/compiled.tar.bz2 on server2. Server2 is where you have logged in currently using ssh/putty. Server1 is the XDA build server from which you want to transfer files.

Of course in some instances, you can omit the -i parameter to the private key by adding the key with ssh-add, to the agent. However I found that Goo, XDA and Sourceforge werent allowing this.

 

Transfer from Local to Remote (Or two remotes, if one of them is logged into)

In this example, I am logged into the XDA build server and am copying a file to my Sourceforge remote server.

 

scp download/phpfm_281012_064121.zip [email protected]:/home/users/d/dr/droidzone

Here, I’m copying a file download/phpfm_281012_064121.zip from the XDA server where I am logged in (or from my linux local machine) to the host web.sourceforge.net to the specified directory. I need to prefix my username. If I need a key, I would prefix it with -i option.

So, essentially, what you have to do is this:

Generate a key pair:

-bash-4.1$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/droidzone/.ssh/id_rsa): /home/droidzone/.ssh/id_rsa_xda
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/droidzone/.ssh/id_rsa_xda.
Your public key has been saved in /home/droidzone/.ssh/id_rsa_xda.pub.
The key fingerprint is:
2d:89:29:71:19:1d:bc:33:d0:cd:60:21:77:00:af:8f [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|      +=BB.      |
|      .B+.o      |
|    . o...       |
|     o ++o       |
|    . + So.      |
|     . o .       |
|      E .        |
|                 |
|                 |
+-----------------+

It doesnt matter where you generate the key files. It could be on your home PC too.

Next, let’s assume you’re going to build on XDA then transfer to Goo.

So. login into XDA (the local server).

Copy the key pair’s private key to XDA, into ~/.ssh/

Change the default permissions to a more secure permission.

chmod go= ~/.ssh/mynewkey

Now, add the public key for this pair to Goo (the remote server)

Edit ~/.ssh/authorized_keys

Go to the end of the last key line. Press enter and paste the new public key.

Save the file.

Now, you can copy the file with the following line:

scp -i ~/.ssh/goo_xda N7100XXALJ3_N7100ODDALJ2_INU.zip [email protected]:/home/droidzone/public_html/firmware/n7100/
N7100XXALJ3_N7100ODDALJ2_INU.zip

This uses the private key ~/.ssh/goo_xda and copies the file N7100XXALJ3_N7100ODDALJ2_INU.zip from the current directory on XDA (where you’re logged into-the local server), into the location /home/droidzone/public_html/firmware/n7100/ on the Goo server (remote). Piece of cake, isnt it?

As you can note, this is extremely useful as XDA does not provide a public_html folder where built files can be provided to users.

Working with Filezilla on XDA’s Build server

Due to the absence of password auth on XDA build server, one needs to setup key based authentication. For this, a third party program named Pageant is required. Another requirement is a key in PPK (Putty) format. The PPK conversion of OpenSSH keys may be done with Puttygen.

Download Pageant from Putty’s site (Choose the x86 version)

Run Pageant.exe (standalone exe)

An icon for pageant appears in the system tray.

Right click it and “Add key”

Choose the ppk key stored for XDA.

Choose Ok.

Start Filezilla, setup the following:

Host: Eg: buildserver.something.xda-developers.com (The actual hostname is provided to XDA RDs)

Port: 22

Protocol: SFTP

Logon type: Normal

Username: [your username]

Password: [leave empty]

Note that if Pageant is working, there is no need to setup key in Filezilla. We just leave an empty password. Pageant takes care of auth.

Transferring large files: rsync

rsync --partial --progress -avvvz -e "ssh -i /home/droidzone/.ssh/xdamachine_key_openssh_pvt" random [email protected]:~/

–partial: Continue interrupted downloads

–progress: Display progress

-a: archive with preserved permissions

-vvv: verbose mode

z: gzip mode transfer

 Rsync exit codes:

  • 0 Success
  • 1 Syntax or usage error
  • 2 Protocol incompatibility
  • 3 Errors selecting input/output files, dirs
  • 4 Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server.
  • 5 Error starting client-server protocol
  • 10 Error in socket I/O
  • 11 Error in file I/O
  • 12 Error in rsync protocol data stream
  • 13 Errors with program diagnostics
  • 14 Error in IPC code
  • 20 Received SIGUSR1 or SIGINT
  • 21 Some error returned by waitpid()
  • 22 Error allocating core memory buffers
  • 23 Partial transfer due to error
  • 24 Partial transfer due to vanished source files
  • 30 Timeout in data send/receive

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Compile and install emacs in a non root Linux environment (XDA and Goo.im)

It’s a Non X, non root environment, typically the XDA build server, you can install and use emacs by the following commands:

mkdir ~/myapps
mkdir sources && cd sources
wget http://ftp.gnu.org/pub/gnu/emacs/emacs-24.2.tar.gz
tar -xvvf emacs-24.2.tar.gz
cd emacs-24.2
./configure --prefix=/home/droidzone/myapps --with-x-toolkit=no --with-xpm=no --with-jpeg=no --with-gif=no --with-tiff=no --with-png=no
make ; make install
export PATH=$PATH:/home/droidzone/myapps/emacs/bin

Compiling and using emacs on Goo.im requires a few additional steps.

If you try configuring emacs directly, you will encounter an error stating that:

configure: error: The required function `tputs' was not found in any library.
These libraries were tried: libncurses, libterminfo, libtermcap, libcurses.
Please try installing whichever of these libraries is most appropriate
for your system, together with its header files.
For example, a libncurses-dev(el) or similar package.[/code]
This is because ncurses library is missing in the Goo server.

So, first download GNU Ncurses and install it:
cd ~/sources
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
tar -xvvf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure --prefix=/home/droidzone/myapps
make
make install

After this, compile Emacs setting the env flag properly to the location where you installed Ncurses

cd ../emacs-24.2
env LDFLAGS=-L/home/droidzone/myapps/lib ./configure --prefix=/home/droidzone/myapps --with-x-toolkit=no --with-xpm=no --with-jpeg=no --with-gif=no --with-tiff=no --with-png=no
make
make install

It is possible to achieve the same by setting
export LD_LIBRARY_PATH=/home/droidzone/myapps/lib before compiling.

 

Compiling mc on Goo

checking for pkg-config... no
*** The pkg-config script could not be found. Make sure it is
*** in your path, or set the PKG_CONFIG environment variable
*** to the full path to pkg-config.
*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config.
checking for glib-config... no
checking for glib12-config... no
checking for glib-config... no
checking for GLIB - version >= 1.2.6... no
*** The glib-config script installed by GLIB could not be found
*** If GLIB was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the GLIB_CONFIG environment variable to the
*** full path to glib-config.
configure: error: Test for glib failed.
GNU Midnight Commander requires glib 1.2.6 or above.

 

On trying to configure pkg-config:

./configure --prefix=/home/droidzone/myapps

./configure: line 13557: --exists: command not found
configure: error: pkg-config and "glib-2.0 >= 2.16" not found, please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure
[email protected]:~/temp/pkg-config-0.27.1$ c

Now, pkg-config configures fine.

Glibc..

configure error

configure: error: linker with -z relro support required

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.