using variables on the command line

Following on from my last example of copying a SSH public key to a remote computer, this is something I need to do when setting up a new computer. Setting up private/public keys for SSH just make logging in that little bit smoother.

When you need to rerun the command, you need to load it up, edit it and resubmit it. Unfortunately (although it’s probably possible) I don’t know an easy way to bring up a previous command and edit it in-line so that I can send it again without actually sending the command again before doing so.

Instead, Load a variable into the command line and change it next time.

-- 11:03:01 -- MBP:~ madivad$ ssh minixbmc
Password:
Last login: Mon Apr 25 18:23:18 2016
minixbmc:~ madivad$ exit
logout
Connection to minixbmc closed.
-- 11:03:17 -- MBP:~ madivad$ remote=minixbmc
-- 11:03:26 -- MBP:~ madivad$  history | grep remote
  439  remote=he1000
  440  cat ~/.ssh/id_rsa.pub | ssh madivad@$remote "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
  502  remote=minixbmc
-- 11:03:34 -- MBP:~ madivad$ !440
cat ~/.ssh/id_rsa.pub | ssh madivad@$remote "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Password:
-- 11:03:40 -- MBP:~ madivad$ ssh minixbmc
Last login: Tue Apr 26 11:03:12 2016 from mbp.fritz.box
minixbmc:~ madivad$

For example, in the above session, for simple commands, I would being the history file up, reissue line 440, then edit, then issue it again. In this situation, it would have the effect of loading the key again, and that’s not what I want to do.

  • Breaking it down, I logged into the remote machine and realised a password was needed,
  • I logged out,
  • I set the “remote” variable,
  • looked for the relevant history command (I knew it had the word “remote” on it),
  • I re-issued that line, and
  • then tested the login.
  • No password was needed, the command was a success.

This could be done with other things as well where you’re always changing one element on the line (or multiple elements, and use multiple variables).

For a more simple and silly example, let’s create a quick update and install script for ubuntu:

upstall=’htop multiwatch’
sudo apt update && sudo apt install $upstall

Instead of typing the whole line next time, I can just type the new apps to install in the “upstall” variable and reissue the command (in this case, using arrow up a couple of times, or grabbing the index from the history file).

$ sudo apt update && sudo apt install $upstall
[sudo] password for madivad:
Hit:1 http://au.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://au.archive.ubuntu.com/ubuntu xenial-updates InRelease [92.2 kB]
Hit:3 http://au.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Fetched 184 kB in 1s (101 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
byobu is already the newest version (5.106-0ubuntu1).
htop is already the newest version (2.0.1-1).
multiwatch is already the newest version (1.0.0-rc1+really1.0.0-1).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

If I then later want do another update and install something else, I can re-set the “upstall” variable and arrow up or grab it out of history.

11:53:44 madivad@he1000:~$ upstall=jq
12:03:44 madivad@he1000:~$ sudo apt update && sudo apt install $upstall
Hit:1 http://au.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://au.archive.ubuntu.com/ubuntu xenial-updates InRelease [92.2 kB]
Hit:3 http://au.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Fetched 184 kB in 2s (91.0 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
jq is already the newest version (1.5+dfsg-1).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
I'm a simple man, I like simplicity. And although there are probably better ways to do this, for the time being, this is how I'm getting the job done. It works well for me, but I'm open to any suggestions and/or improvements.

As I said, not the best example, but hopefully you get the idea.

What files is my program trying to access?

In this example I’m using hashdeep. I’m redirecting the output of two hash sets to two different files. I am doing that with the following command:

hashdeep -rj0 /path-to-drive-1 > hashes.drive1

and

hashdeep -rj0 /path-to-drive-2 > hashes.drive2

I have those running in their own terminal windows. I then optionally have another two windows open running a tail on them so I can monitor the files:

tail -f hashes.drive1

The hard drives are located in an external multi-bay enclosure and all hard drive LEDs are flashing away like mad. A good sign. But every now and then I’ll run an ‘ls’ to see where the files are at (checking file size) or alternatively (and usually better but more resource intensive) a line count of the hash files. Given I know how many files there should be, the line count gives a fair indication of the progress of the whole process.

wc -l hashes.drive*

In today’s example I was simply doing a file size comparison of the two hashes vs a known hashset of one of the drives that was a month old. The sizes should be relatively similar. I was getting results similar to:

madivad@server:~$ ls -al hashes*
-rw-rw-r-- 1 madivad madivad 330483319 Feb 11 09:26 hash.drive1.1602
-rw-rw-r-- 1 madivad madivad 341570757 Mar 23 12:09 hash.drive1.1603
-rw-rw-r-- 1 madivad madivad 243344728 Mar 23 11:18 hash.drive2.1603

The fact that drive1.1603 is larger is of no consequence, there are just more files to consider.

After running the above check for sometime, I realised that one of the files (in this case drive1.1603) had stalled for several hours. I’m not exactly sure when it seemed to stop growing, but doing a tail of the file confirmed it was stopped. The last output was an inconsequential .DS_Store file roughly 6K in size. After physically monitoring it for some time I began to get concerned about this. I could see the all 4 RAID drives getting activity, but nothing was being recorded. The 5th drive, the backup, was hashing away without a problem and the log file was growing as expected.

After some quick research I came across this stack exchange Q&A ( How do I know which file a program is trying to access? )

The first answer provided a solution that worked best with my scenario:

lsof -c hashdeep

I’d never seen this output before but very quickly I could see the important pieces of information it had dumped out. Namely:

madivad@server:~$ lsof -c hashdeep
COMMAND  PID  USER    FD TYPE DEVICE     SIZE/OFF  NODE       NAME
hashdeep 2539 madivad 1w REG  252,0     243344728  5535319    /home/madivad/hash.drive1.1603
hashdeep 2539 madivad 3r REG  259,0  499418030080  113639426  /path1/largeFiles/a-very-big-image-of-500GB.img
hashdeep 2552 madivad 1w REG  252,0     341611062  5535320    /home/madivad/hash.drive2.1603
hashdeep 2552 madivad 3r REG  8,33     3152347139  126025746  /path2/misc/random.file

The ‘w’ of FD with ‘1w’ signifies the file is being written and that the file being written was hash.drive1.1603

The ‘r’ of FD with ‘3r’ signifies the file is being read for hashing purposes, and that file is a very large file that I know is around 500GB. Running the command again shows me the second file being read in had changed, yet the first had stayed the same.

Given the file is very large and will take considerable time to hash and that the hard drive LEDs are flashing, I realised all was good in the world and I could move on with the days activities.

UPDATE: after reading the man page on lsof I found a better way to monitor the continual progress of it was to run it with the -r “repeat” switch which defaults to 15 seconds, which could be updated more or less frequently by adding a numerical component:

lsof -r 5 -c hashdeep

How to setup BASH custom prompt in Ubuntu

I wanted two things:

  • the time in my prompt
  • a colour prompt

Basics:

  • it’s located in: ~/.bashrc
  • uses Environment Variable: PS1
  • time is inserted using: \t

time

I started here: http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

colour

http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/

PixelBeat discussion on coloured command prompts

http://www.pixelbeat.org/docs/terminal_colours/

how to guid for customing the command prompt

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/

ZFS on Ubuntu 14.04

I’ve completed a fresh install of Ubuntu on an old box that use to contain solaris. The system disk died and upon installing a new (old) drive and then installing ubuntu, I found that two of the disks still in the computer were part of a zfs raid. I’m not sure how many disks were in the raid, but I’m curious as to what was on this file system that has been shutdown in inaccessible for more than 7-8 years. (I later confirmed that most files on the system are from 2008 and earlier).

There were only 4 available sata connectors to the board. Two were used for the drives in there, it didn’t take long to find the matching drives to plug in.

Installing ZFS

I began with installing zfs by following the instructions here:
Install ZFS on Ubuntu—Server as Code

Installing SSH Server

I also had to install an SSH Server because this is on a box located remotely. Follow any generic install of Open SSH Server. The one I used was SSH/OpenSSH/Configuring.

Because my server is behind a firewall and not publicly accessible, I haven’t worried too much about logon via SSH Keys. I have done it before, but this box is only going to be a temporary install, but I do recommend you do that. A couple of other related tutorials to passwordless ssh key access to servers:
https://help.ubuntu.com/community/SSH/OpenSSH/Keys << a good resource, includes troubleshooting
http://www.mccarroll.net/blog/rpi_cluster2/index.html
https://www.howtoforge.com/tutorial/ssh-and-scp-with-public-key-authentication/
https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md

Installing Samba

I also installed samba, following these instructions How to Create a Network Share Via Samba Via CLI (Command-line interface/Linux Terminal) – Uncomplicated, Simple and Brief Way!

With SSH, Samba and the ZFS modules installed, configured and running… let’s try and rebuild this raid :)

Let’s have a look!

disks:

lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                            8:0    0 111.8G  0 disk 
├─sda1                         8:1    0   243M  0 part /boot
├─sda2                         8:2    0     1K  0 part 
└─sda5                         8:5    0 111.6G  0 part 
  ├─ubuntu--vg-root (dm-0)   252:0    0 110.6G  0 lvm  /
  └─ubuntu--vg-swap_1 (dm-1) 252:1    0  1016M  0 lvm  [SWAP]
sdb                            8:16   0 698.7G  0 disk 
├─sdb1                         8:17   0 698.6G  0 part 
└─sdb9                         8:25   0     8M  0 part 
sdc                            8:32   0 698.7G  0 disk 
├─sdc1                         8:33   0 698.6G  0 part 
└─sdc9                         8:41   0     8M  0 part 
sdd                            8:48   0 698.7G  0 disk 
├─sdd1                         8:49   0 698.6G  0 part 
└─sdd9                         8:57   0     8M  0 part 
sde                            8:64   0 698.7G  0 disk 
├─sde1                         8:65   0 698.6G  0 part 
└─sde9                         8:73   0     8M  0 part 
sr0                           11:0    1  1024M  0 rom

and for pools specifically:

$ sudo zpool import
   pool: solaraid
     id: 10786192747791980338
  state: ONLINE
 status: The pool is formatted using a legacy on-disk version.
 action: The pool can be imported using its name or numeric identifier, though
	some features will not be available without an explicit 'zpool upgrade'.
 config:

	solaraid                                       ONLINE
	  raidz1-0                                     ONLINE
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN         ONLINE
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT         ONLINE
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT         ONLINE
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT         ONLINE

Ok, this PC only had 4x SATA drives and it appears I’ve found the correct drives. Things are looking good from the start.

Let’s do it!

:~$ sudo zpool import solaraid
:~$ sudo zpool status
  pool: solaraid
 state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
	continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Wed Nov 11 21:37:59 2015
    11.5M scanned out of 1.63T at 1.15M/s, 412h58m to go
    2.60M resilvered, 0.00% done
config:

	NAME                                           STATE     READ WRITE CKSUM
	solaraid                                ONLINE       0     0     0
	  raidz1-0                              ONLINE       0     0     0
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     2  (resilvering)

errors: No known data errors

YOUCH! 412HOURS… That’s 17 days! I gave it a couple of seconds to stabilise and ran it again, and came up with an error:

:~$ sudo zpool status
  pool: solaraid
 state: ONLINE
status: One or more devices has experienced an unrecoverable error.  An
	attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
	using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://zfsonlinux.org/msg/ZFS-8000-9P
  scan: resilvered 2.60M in 0h0m with 0 errors on Wed Nov 11 21:38:24 2015
config:

	NAME                                           STATE     READ WRITE CKSUM
	solaraid                                ONLINE       0     0     0
	  raidz1-0                              ONLINE       0     0     0
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     2

errors: No known data errors

Reboot and Ubuntu bootup fail

(long winded fluff about nothing, you can scroll down to “Resilvering” if you’d like to skip this)

I do recall I had issues with this raid, I could certainly go the route of upgrading it first and trying it again, but once I did a

tree -L 2 /solaraid/

and seeing things I had long thought were gone, I’m going to back this up first :)

The only problem is, the raid is installed in a box with only a 10/100 network card :(

I’ll let it run overnight taking off only what I need, and see how we go. This has been a good find

At this point I was operating in the house and the server is located off-site. I had several ssh/terminal windows open to the box and as I was working away I kept getting the message to reboot the system. I issued the relevant reboot command and set off a ping to tell me when it came back online… It didn’t come back online.

I went to the server and found it was still booting. This was after more than half an hour and eventually it gave up and crashed and restarted again.

For the next couple of hours I could not get the drive to boot and I was blaming the old boot drive, but after eventually getting into the “Try Ubuntu” mode from the DVD I found that one of the drives were not being reported in the system. Another was coming up as totally unknown and two were seen as part of a set. It took several hours to get to the bottom of it. Eventually thru the BIOS I could see one of the drives weren’t being detected.

A couple of sata cable changes and swapping power cables around and I was back in business.

Resilvering

:~$ sudo zpool status
  pool: solaraid
 state: ONLINE
status: One or more devices has experienced an unrecoverable error.  An
	attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
	using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://zfsonlinux.org/msg/ZFS-8000-9P
  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    1.73G scanned out of 1.63T at 32.3M/s, 14h40m to go
    12.5K repaired, 0.10% done
config:

	NAME                                           STATE     READ WRITE CKSUM
	solaraid                                ONLINE       0     0     0
	  raidz1-0                              ONLINE       0     0     0
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0    13  (repairing)
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0

errors: No known data errors

Over the next few minutes I kept polling the status and it was picking up speed.

  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    24.3G scanned out of 1.63T at 84.5M/s, 5h31m to go
    12.5K repaired, 1.46% done
  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    32.1G scanned out of 1.63T at 97.0M/s, 4h47m to go
    12.5K repaired, 1.93% done
  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    56.9G scanned out of 1.63T at 102M/s, 4h29m to go
    12.5K repaired, 3.42% done
  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    184G scanned out of 1.63T at 137M/s, 3h4m to go
    184K repaired, 11.01% done

It’s starting to slow down again, and we’re seeing more errors!

  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    195G scanned out of 1.63T at 93.6M/s, 4h28m to go
    354K repaired, 11.68% done

The next day and something had gone wrong. I’m still unsure what happened, but the whole `solaraid` drive became unresponsive.. Where it had got to the evening(/morning before) at 195GB in the resilvering is where it was when I checked it later today. And the drive was otherwise not responding. I remotely tried to reboot and again it hanged.

At this present time, I’m still putting it down to hardware, but it’s really unknown what’s at the root of the problem.

It’s been back up and running for a while now and it’s present status is:

  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    1.41T scanned out of 1.63T at 160M/s, 0h23m to go
    1.23M repaired, 86.89% done
config:

	NAME                                    STATE     READ WRITE CKSUM
	solaraid                                ONLINE       0     0     0
	  raidz1-0                              ONLINE       0     0     0
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0   251  (repairing)
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     6  (repairing)

errors: No known data errors

When I captured the above, I hadn’t realised the process was almost finished until I pasted and read over it.

  scan: scrub in progress since Thu Nov 12 03:12:54 2015
    1.62T scanned out of 1.63T at 158M/s, 0h0m to go
    1.29M repaired, 99.46% done

As I write this the process has been running for exactly 24 hours. We have 0.5% left.

The final capture:

:/solaraid$ sudo zpool status 
  pool: solaraid
 state: ONLINE
status: One or more devices has experienced an unrecoverable error.  An
	attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
	using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://zfsonlinux.org/msg/ZFS-8000-9P
  scan: scrub repaired 1.29M in 12h0m with 0 errors on Thu Nov 12 15:13:05 2015
config:

	NAME                                    STATE     READ WRITE CKSUM
	solaraid                                ONLINE       0     0     0
	  raidz1-0                              ONLINE       0     0     0
	    ata-WDC_WD7500AACS-00C7B0_WD-WCASN  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0     0
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0   291
	    ata-WDC_WD7500AAKS-00RBA0_WD-WCAPT  ONLINE       0     0    12

errors: No known data errors

The resilvering has checked every checksum in 1.6TB of data and repaired 1.29MB. The process took exactly 12 hours (with a reboot thrown in there JUST to push the boundaries a little bit).

Next we’re to get any data off that we want… Let’s grab some directory information
To be continued…

sudo please

I stumbled across this alias quite a few months ago, but it was under a different name then.

I wanted to find it today and Google searches brought up a whole heap of malicious finds on it, aimed at targeting the unsuspecting newbie to linux. Obviously there are some very dangerous linux commands and so I’m not going to repost them here. Or maybe.

In linux, when you need special permissions to run a command, you’ll get a “permission denied” error. The standard response to that is to “sudo !!” (pron: sudo bang bang) which runs the last command again. Everyone who’s ever used linux will know this can get frustrating.

The I found “fuckit” (or it could have been just “fuck”, I can’t remember which).

When you forget to type sudo, and you’re prompted your permission has been denied, you can issue the expletive whereby the command runs as expected. The funny thing about this, is that when this does happen, it is the sort of thing you are probably thinking, and the expletive does it’s job.

In looking for it today, I found that someone else uses the “please” alias instead. There’s no difference, they both do the same job. It’s just how you feel you want to talk (type) to your computer at the time.

To achieve this, you need to create an alias:

alias please='sudo $(fc -ln -1)'
alias fuck=please

Only include the second line if you feel so inclined. I did because initially you can be all like “please?? Oh thank you understanding computer.” but after a day of permission denied errors, you might be more inclined to just yell at the screen, in which case, the second line is more appropriate.

Creating the alias alone won’t make it persistent. To do that, add the alias to the end of your ~/.bashrc file, or in my case, I’m running ubuntu and you can add it to ~/.bash_aliases instead.

Ubuntu – changing DHCP to Static

Before jumping in and making the changes, do
ifconfig -a
and note down any particular settings which you may need (if you don’t already know them)

Then edit /etc/network/interfaces

change:

iface eth0 inet dhcp

to:

iface eth0 inet static
address 10.0.0.101
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.100

May also need to add nameservers to /etc/resolv.conf, eg:
nameserver 10.0.0.100
nameserver 192.122.108.211

Obviously change to suit your network settings.

Once done, don’t forget to restart the networking interface

sudo /etc/init.d/networking restart

Synergy in OpenSolaris and Ubuntu

I have been tinkering with linux distros for a while now, my favourite (generally) would have to be Ubuntu. It is one of the few that installs quickly and simply on most of my systems here.

A package I also use is Synergy. This is one of the best pieces of software ever developed for multi-desktop computing. Much better than VNC and Remote Desktop, although they each serve their purpose and offer different functionality.

To learn more about Synergy, visit http://synergy2.sourceforge.net/

To learn how to install it in OpenSolaris (I am using preview 2) it is simply a matter of:
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/libgcc-3.4.6-sol10-x86-l...
gunzip libgcc-3.4.6-sol10-x86-local.gz
pkgadd -G -d libgcc-3.4.6-sol10-x86-local
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/synergy-1.3.1-sol10-x86-...
gunzip synergy-1.3.1-sol10-x86-local.gz
pkgadd -G -d synergy-1.3.1-sol10-x86-local

You have to make sure that /usr/local/bin is in your path.

tip: I use/prefer BASH, to edit the user path for BASH in OpenSolaris you HAVE to edit the file .bashrc located in your home directory. Editing it anywhere else will have no effect since (in Preview 2) this file explicitly defines the path WITHOUT inheriting the original path. You have been warned (it took me a few hours to find this!)

for ubuntu there is an excellent walkthru here: https://help.ubuntu.com/community/SynergyHowto

note: for the ubuntu install, make sure you have added the universe repositories http://dav3.net/ubuntu/repositories

Adding Ubuntu Repositories

In a nutshell
edit the file /etc/apt/sources.list

You can edit it from the command line ( http://help.ubuntu.com/community/Repositories/CommandLine ) or use the GUI from the Ubuntu desktop: System –> Administration –> Software Properties and add to the repositories by adding a channel (the add button). You can also add new repositories there as well.

For a very well documented HOWTO: visit http://help.ubuntu.com/community/Repositories/Ubuntu

SSH Server in Ubuntu

To securely administer your Ubuntu Server remotely, you need to install SSH server. SSH provides you with a secure connection to your server and allows you to run commands all as if you were logged in at the terminal itself.

To install SSH server in Ubuntu
$ sudo apt-get install openssh-server

All going well, your install is complete. your RSA and DSA keys have been created and you have a default config file.

Connecting to the server
To connect to the server from other machines use ssh (on *nix computers or putty on windows systems). You log into the machine by typing:

$ ssh 192.168.0.4 or c:\>putty 192.168.0.4
(this is an example IP address, use whatever IP address is assigned to the server)

Configuring SSH
There is a default config already with the SSH Server, you can chop and change it to suit your needs. For security you may want to disable root logins and X11Forwarding. If you don’t know what they are, then you probably do want to disable them anyway. The configuration file you want to edit is /etc/ssh/sshd_config

Disable remorte root logins
Search for and edit the following line in the /etc/ssh/sshd_config file:

PermitRootLogin yes
and change it to:
PermitRootLogin no

Disable X11 forwarding
Same file as above, search for and change the following line:

X11Forwarding yes
to:
X11Forwarding no

Restart the SSH Server
After you have made these changes, you will need to restart the SSH server. At the command prompt type:
$ sudo /etc/init.d/ssh restart

More on X11 Forwarding
If you want to use X11 Forwarding option so that you can connect your remote machine desktop using Xterm if you want to connect the X11 session you need to use the following command

ssh -X serveripaddress

Copy Files Securely using SCP
Another common need is to be able to copy files between servers you are administering. While you could set up FTP on all of the servers, this is a less-than-ideal and potentially insecure solution. SSH includes within it the capability to copy files using the scp command. This has the added benefit of copying the files over a secure channel along with taking advantage of any key-based authentication you might have already set up.

To copy a file to a remote machine use the following command

scp /path/to/file user@remotehost:/path/to/destination

If you need to copy from the remote host to the local host, reverse the above command

scp user@remotehost:/path/to/file /path/to/destination

if you need to copy an entire directory full of files to a remote location, use the -r argument

scp -r /path/to/directory/ user@remotehost:/path/to/destination/

If you are transferring logfiles or other highly compressible files, you might benefit from the -C argument. This turns on compression, which, while it will increase the CPU usage during the copy, should also increase the speed in which the file transfers.

Use the -l argument to limit how much bandwidth is used. Follow -l with the bandwidth you want to use in kilobits per second. So, to transfer a file and limit it to 256 Kbps use the following command

scp -l 256 /path/to/file user@remotehost:/path/to/destination

RAR in Ubuntu

IMHO RAR is a dying archive format, except in the torrent and related warez world. Why? I don’t know. But what I do know (now) is how to install RAR for linux under Ubuntu 6.10 (Edgy) and this is it:

Download rarlinux, the version I got was 3.6.0 and I found it here:

http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz

(you can use ‘wget’ from a linux console to grab it)

ungzip the file:

tar -zxvf  rarlinux-3.6.0.tar.gz

Now for some reason when i did this the first time, it didn’t fully unzip and I had to process the tar file again, but on another machine both steps were done with the above command. If you have a rar folder now, then skip the next command, but if you have a new file with the name rarlinux-3.6.0.tar (ie, no .gz ext) then untar it with the following:

tar -xvf rarlinux-3.6.0.tar

then change into the rar directory created, and you only need to copy the ‘rar’ file into your “/user/bin” directory

cd rar
cp rar /user/bin/.

use “rar” at the command line without any options to get an overview of the switches and commands associated with it