Showing posts with label commands. Show all posts
Showing posts with label commands. Show all posts

Sunday, 19 August 2012

SSH client and daemon: Introduction


SSH client application allows you to logging in a remote computer, or execute commands remotely.

It is also able to execute graphical applications, and to forward TCP ports from and to local and remote machines.

SSH establishes a securely encrypted communication between local and remote hosts along an insecure network.

For SSH client to work it needs to connect to a SSH server in the remote computer.


INSTALL SSH AND SSHD


SSH program binaries are:

ssh — OpenSSH SSH client (remote login program)
sshd — OpenSSH SSH daemon


In Debian or Ubuntu:

$ sudo aptitude install openssh-client # installs ssh client

$ sudo aptitude install openssh-server # installs sshd daemon


CONFIGURE SSH CLIENT

Saturday, 24 December 2011

Git Command Quick Reminder

NOTE: You can find an updated version of this article in Git Command Quick Reminder


INSTALLING GIT
$ aptitude install git-core # git basic tools.

NOTE: In Debian Unstable
$ aptitude install git


gitk graphic tool.
$ aptitude install gitk # this graphic tool allows us to browse a git repo.



INITIALIZE A REPOSITORY

$ git init # Creates an empty repository in current directory, or reinitializes an existing one.
$ git init directory_name # Creates an empty repo in directory_name directory.

$ git clone remote_url # clone a remote repo. Passing as argument a local directory this command clones a local repo.

$ git clone --depth 1 git://git.sip.router.org/sip-router kamailio # clones sip-router source code, creating a local directory named kamailio. "depth 1" option means it only takes one revision history. That reduces the amount of history to download, but it disallows cloning, fetching, pushing or pulling from this repo. Then, it is only suitable to generate patches.

$ git clone source_repo dest_repo # clones a local repository source_repo in another local repository dest_repo,
if both are directories.
$ git clone file:///path/to/source/repo file:///path/to/dest/repo # another way to specify local directories.
This way we are sure git does not use hard links when cloning source repo.
$ git clone --no-hardlinks source_local_repo dest_local_repo # clone a repository and copy object files instead of using hardlinks for local repo objects.


GIT SVN

Sunday, 30 March 2008

GNU/Linux SYSTEM DIRECTORIES and their FILESYSTEMS

Executing $ ls / lists the top level of the root filesystem tree. There appear directories like:
/dev, /etc, /proc, /sys, /var, /tmp and others.

In this article we are going to deal with directories that have special filesystems associated with them.


For a general view of the filesystem hierarchy we can visit the Filesystem Hierarchy Standard page.

FHS standard is a set of guidelines about where to place files and directories within UNIX based operating systems.


Check which filesystems are mounted


Two commands allow us to examine which filesystems and where are currently mounted in our system.

$ mount
or
$ cat /etc/mtab


Their response will be something like that:
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.22-14-generic/volatile type tmpfs (rw)
securityfs on /sys/kernel/security type securityfs (rw)


We are specially interested in /proc, /sys, /var/run, /var/lock, /dev, /dev/shm, /dev/pts, /sys/kernel/security




/proc directory

Friday, 14 March 2008

GNU Readline Library Short Description

GNU Readline is a software library that provides a set of functions that allow users to edit command lines as they are typed in.

Every program that uses this library provides the same user command line interface improving consistency between applications.

It is part of the GNU Project and it is licensed under the GPL.

Current version is 5.2 and it is used in projects like bash.

There are two editing modes available: Emacs (default) and Vi

Readline library includes additional functions to maintain a list of previously-entered command lines.
Exec this command to obtain more info about this feature:
$help history


INSTALLATION

In Debian and Ubuntu this library is packed in readline-common package.
$sudo aptitude install readline-common

Once installed, you can access a complete documentation using info command:
$info rluserman


SHORT KEYSTROKE REMINDER

NOTATION:
C-k means while ctrl key is mantained pressed, depress 'k' key.
M-k means while "meta" key is pressed, depress 'k' key.

Usually "meta" refers to ALT key, but if you have no meta key you can use ESC key instead.


Emacs mode commmands:

Movement

C-b Move back the cursor one character.
C-f Move one character forward.
DEL or Backspace Delete the character placed left at the cursor.
C-d Delete the character underneath the cursor.
C-_ or C-x C-u Undo the last editing command.

C-a Move to the beginning of the line.
C-e Move to the end of the line.
M-f Move forward a word.
M-b Move backward a word.
C-l Clear the screen, reprinting the current line at the top.

Killing and yanking (cutting and pasting) commands

C-k Kill the text from the current cursor position to the end of the line.
M-d Kill from the cursor to the end of the current word.
M-DEL Kill from the cursor the start of the current word.
C-w Kill from the cursor to the previous whitespace.

After killing(cutting) text, we yank(paste) it back into the line.

C-y Yank the most recently killed text back into the buffer at the cursor.
M-y Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or M-y.

Searching commands

C-r Searchs backwards on the previous commands you typed.
C-s Perform a forward search from the command line history you are now.

Passing arguments to a command

e.g: M-2 3 C-d means delete next 23 characters on input line.



CONFIGURING THE LIBRARY

GNU Readline keybindings and more can be changed editing ~/.initrc or /etc/initrc files.


URLs
GNU Readline Official page
GNU Readline (Wikipedia)
Official online Readline documentation

Tuesday, 19 February 2008

Bash tips II

RETYPING A COMMAND YOU TYPED SEVERAL LINES BEFORE

Sometimes you have to type a command you typed before, but you don't want to write it again, or don't remember exactly what you wrote on your command prompt.
Solution is easy, we are gonna use reverse search!

Press the keys: ctrl+r and then type part of the command you want to retype.
NOTE:It is not necessary to write the beginning of the command, you can write whatever part you want for reverse search.

If reverse search has found a command but it is not the one you were searching for, type ctrl+r again till you find it, or write a better part of the command at search time.


Now we have found the command, we have two options:
- pressing enter, the command will be executed
- pressing tab key we will be able to edit this command at the bash prompt prior to its execution.


CHANGING INTO ANOTHER DIRECTORY but memorizing where we are now in order to return later easily

This is useful if you have long weird named paths.

We are now located at foo directory:
:/foo$pwd
/foo


We want to change into bar directory, instead of using cd command we use pushd
:/foo$pushd /bar

Now we are in /bar directory:
:/bar$pwd
/bar


In order to return to prior foo directory we only have to run popd command.
:/bar$popd

:foo$pwd
/foo


CHECKING FOR BAD BLOCKS IN A PARTITION

Sometimes we want to check the blocks of a hard disk we have just bought, or whatever...

We have two options:

  • First time, when creating the filesystem with '-c' option

    e.g: mkefs.ext3 -c -b 4096 -L foo /dev/sdb2


  • If the filesystem at this partition has been already created we can use badblocks command.

    NOTE: Read carefully badblocks man page, $man badblocks before doing anything potentially harmfull.

    e.g: sudo badblocks -v /dev/sdb2

Saturday, 7 July 2007

Apt, Aptitude and Dpkg Reference

Apt, Aptitude and Dpkg are Debian package managing tools. Let's see a small reference about them:

# apt-get install foo ....................... Installs foo package
# apt-get remove foo ........................ Removes foo package
# apt-get remove --purge foo ................ Removes foo package and its configuration files.
# apt-get update ............................ Updates package database.
# apt-get -f install......................... Installs and removes packages in order to fix dependency problems.
# apt-get clean ............................. Deletes all .deb packages from local repository.
# apt-get upgrade ........................... Upgrades all packages to its newer versions.
# apt-get dist-upgrade ...................... Upgrades packages but also deals with dependency problems caused by new packages.
$ apt-get source foo ........................ Downloads foo package source files.
# apt-get -t unstable foo ................... Installs foo package searching for foo package and its dependencies at unstable version.
# apt-get foo/unstable ...................... Installs foo package from unstable version, but searchs for dependencies without overriding priorities at /etc/apt/preferences file.
# apt-get build-dep foo ..................... Installs all necessary packages to satisfy the build dependencies for foo source package.

$ apt-cache show foo ........................ Gives a long info description about foo package.
$ apt-cache search foo ...................... Searchs for packages that match "foo" pattern.

# apt-file update ........................... Resynchronize the package contents from their sources (/etc/apt/sources.list)
$ apt-file search foo ....................... Lists all packages containing files that match foo pattern. Searchs also in not installed packages.

# aptitude install foo ...................... Installs foo package
# aptitude remove foo ....................... Removes foo package
# aptitude remove --purge foo ............... Removes foo package and its configuration files.
$ aptitude search foo ....................... Searchs for packages that match "foo" pattern
# aptitude update ........................... Updates package database.
# aptitude upgrade .......................... Upgrades packages to its newer versions.
# aptitude safe-upgrade ..................... Same as aptitude upgrade.
# aptitude full-upgrade ..................... Upgrades packages to its newer versions, taking care about dependencies. Sames as dist-upgrade.
# aptitude hold foo ......................... Marks foo package so it will not be removed or upgraded when executing safe-upgrade or full-upgrade
# aptitude unhold foo ....................... Turn off the hold on foo package.
$ aptitude show foo ......................... Gives a long info description about foo package.
# aptitude clean ............................ Removes all previously downloaded .deb files from the package cache directory.
$ aptitude download foo ..................... Downloads foo package to current directory.
#aptitude build-deps foo .................... Installs all binary dependencies needed to build foo source package.

# dpkg -i foo ............................... Installs foo package
# dpkg -i --force-depends foo ............... Converts all dependency errors into warnings and installs foo package.
# dpkg -r foo ............................... Removes foo package
# dpkg --purge foo .......................... Removes foo package and its configuration files too.
$ dpkg -l *foo* ............................. Lists packages containing "foo" pattern.
$ dpkg -L foo ............................... Lists files pertaining to foo package.
# dpkg-reconfigure -plow foo ................ Reconfigures previously installed "foo" package, asking all configuration questions.
# dpkg --configure -a ........................... Configures all packages that have been unpacked but not yet configured.
$ dpkg --search foo ......................... Lists packages containing files matching foo pattern. Only searchs on installed packages.
$ dpkg -c foo.deb ........................... List files contained in foo.deb package.
$ dpkg -I foo.deb ........................... Shows info about foo.deb package.

$ dpkg-query -S foo ......................... Searchs for a filename from installed packages listed in the local dpkg database.

$ dpkg-buildpackage -us ..................... Builds debian package from its source code.


More info at:
The Debian package management tools.
APT Howto.
Debian package management.

Sunday, 17 June 2007

Bash tips

http://builder.com.com/5100-6372_14-5827311.html

Customizing the bash command prompt




COMMAND REFERENCE

Linux Command Reference Index

Another command Reference

O'Reilly Command Reference

GNU/Linux Command Line Tools Sumary

Learning the Shell Tutorial





Changing X resolution

$xrandr #shows all available resolutions
i.e:
SZ: Pixels Physical Refresh
*0 1024 x 768 ( 271mm x 203mm ) *61
1 800 x 600 ( 271mm x 203mm ) 73
2 640 x 480 ( 271mm x 203mm ) 73


now, to switch to 800x600 resolution we can exec:

$xrandr -s 1

or

$xrandr --size 800x600

wait for 5 secs and voila! resolution changed!

NOTE: another way to change resolution is pressing ctrl+alt++ or ctrl+alt+- keys

NOTE: this command is very useful to change qemu X-windows resolution when it is bigger than your screen.




Listing file sizes in human readable form:

ls -l # shows file sizes, usually in bytes.

if you want to list them in a more readable way type:

ls -lh

NOTE: this "h" switch option also works with other commands like df, du, etc.




Obtaining an ISO file from a CDRom

You need to now what device your cdrom drive is associated to: (In this example will be /dev/sdX)

exec this command:
dd if=/dev/sdX of=cdrom_image.iso bs=1000000

that makes a byte by byte copy from /dev/sdX device (our cdrom) to cdrom_image.iso file in 1000000 bytes size chunks.

NOTE: Change bs argument to suit your needs. That value has effect on the speed the copy is performed.