NOTE – one of the most frequent account modifications in Linux is to change a user’s password. You can do this with the passwdprogram. Simply type the sudo passwd USERNAME command. For example, to change the password of the user jwilliams, simply typesudo passwd jwilliams. This will open up the prompt where you can enter the new password.
Modifying users
Dr Hjkl on the Command Line
The first time I used vi was in a college programming course. It was thedefault editor on the computer lab's UNIX systems we used to compile ourassignments. I remember when our professor first introduced vi andexplained that you used the hjkl keys to move your cursor around instead ofthe arrow keys. Before this point, I was a pico user (that dates me a bitnow), and it seemed so backward to me that vi used hjkl instead.
It wasn'tuntil I became a heavy vim user that I began to appreciate the speed yougain from navigation keys appearing on home row. As a touch typist, Irealized the arrow keys are in a no-man's land outside the home rowcompared to hjkl, and even though vim supported arrow keys, I used hjklinstead. I've been pleased to discover a number of different programs thatalso support the same level of key bindings.
I've written a few othercolumns in Linux Journal through the years along those lines (all with DrHjkl in the title), and here, I've decided to revive Dr Hjkl foranother round of time-saving command-line navigation tips that will help keepyour hands on the home row and off those arrow keys.
Most of my tips in this article are about reducing your reliance on thearrow keys and increasing your speed when on the command line. For manyyears, whenever I would find a mistake in a command I typed, I would do oneof two things: use a combination of Home, End and the arrow keys (all waytoo far away from home row) to move the cursor back to the mistake so Icould fix it, or sometimes I found it was faster to press Ctrl-C and type thewhole command again. One day I observed another Linux user fly back andforth across words on the command line and realized there was a better way.
Moving Between WordsThe first simple speed improvement is the use of Alt-b and Alt-f to movebackward or forward one word on the command line. This behaves somewhatlike the b and w keys in vi to skip between words instead of one letter ata time. Alt-b acts like just like b in vim. Press Alt-b, and the cursor willmove back one word and sit at the first letter of the previous word. Alt-fis slightly different; the cursor moves forward until it ends up at thespace between words instead of at the beginning of the following word. Sogiven the following command:ls -l /var/log
If my cursor were at the end of the line and I pressed Alt-b, it now would beover the l in log. If I pressed it again, it would move to the v in var. If mycursor were at the beginning of the line and I pressed Alt-f, it would end upon the space between ls and -l. This annoys me enough that often I'll findmyself going forward an extra word and then pressing Alt-b sothe cursor is where I want it. Even though it's more keystrokes than theright-arrow key, it keeps my hands on the home row. Alternatively (as you'llsee later), I simply could press Ctrl-f to move forward an extra letter instead.
Delete WordsThe bulk of the time that I use Alt-b and Alt-f on the command line is tocorrect a typo earlier in the line. Now, you certainly could move the cursorover to the right position and then use Delete or Backspace to erase theerror, but for minor mistakes, I've found it's much faster to delete thewhole word and retype it. In vim, I would type cw to change the word undermy cursor, or a slightly slower approach is to type dw to delete the wordand then enter insert mode to make my changes. On the command line, youcan replicate the behavior of dw with Alt-d. The Alt-d key will remove the word under the cursor completely so you can retype it. So,taking thesame example from above:ls -l /var/log
If my cursor were at the end of the line and I realized I wanted to change-l to -ltr, I would press Alt-b three times to move it over the l in -l, thenI would press Alt-d to delete the l, and finally type ltr.
Replace Home and EndIt turns out the arrow keys aren't the only ones on the hit list. Home andEnd, although useful, also are out in that no-man's land away from the homerow.In vi, you would just use ^ or $ to go to the beginning or end of the line.On the command line, you can replace Home and End with Ctrl-a and Ctrl-e,respectively. If you use screen or tmux with screen key bindings, you knowthat Ctrl-a already is called for, so you'll need to press Ctrl-a a to sendthat Ctrl-a through to the command line. Ctrl-a can be particularly usefulwhen you realize you need to pipe some initial command through somethingyou've already typed, and Ctrl-e is useful to move back to the end of theline afterward to finish your command after editing it somewhere in themiddle.
A Few Final ShortcutsAlthough the above shortcuts are enough to get started, before I finish, Iwant to highlight a few extra shortcuts that are less useful but worthknowing all the same. First, although Alt-b and Alt-f move backward andforward a word, respectively, their counterparts Ctrl-b and Ctrl-f willmove backward and forward a single letter. Somewhat less useful, but stillinteresting, is the fact that you can use Alt-u to uppercase the full wordunder the cursor, Alt-l to lowercase the word, and Alt-c to capitalize thefirst letter in the word.
With all of these tips, I recommend posting a reminder to yourselfsomewhere on your computer. It may take a few weeks to ingrain a new habitlike this into your command-line use, but once you get used to it, you won'tgo back. I've found that these shortcuts also apply in command-lineclients like Irssi, so if I notice I have a typo in something I'm about tosay in IRC, I can just press Alt-b until it's under the cursor, and press Alt-d todelete it, and then correct the error and press Enter.
Initializing and Managing Services in Linux: Past, Present and Future
One of the most crucial pieces of any UNIX-like operating system is theinit dæmon process. In Linux, this process is started by the kernel,and it's the first userspace process to spawn and the last one to dieduring shutdown.
During the history of UNIX and Linux, many init systems havegained popularity and then faded away. In this article, I focus on thehistory of the init system as it relates to Linux, and I talk about therole of init in a modern Linux system. I also relate some of the historyof the System V Init (SysV) scheme, which was the de facto standard for manyLinux distributions for a long time. Then I cover a couple moremodern approaches to system initialization, such as Upstart and systemd.Finally, Ipay some attention to how things work in systemd, as this seems to bethe popular choice at the moment for several of the largest distributions.
The Role of InitInit is short for initializer, and it's both a startup manager and asession manager for Linux and other UNIXes. It's a startup manager,because it plays a crucial role in the startup of Linux. It's theprocess that creates or initializes userspace and, ultimately, alluserspace processes. It also may be considered a session manager,because it takes care of many aspects of userspace and its processesonce the system is up and running.
The call to start this process is, in fact, hard-coded in the Linuxkernel. Download the latest kernel sources and look for a functioncalled kernel_init in the file init/main.c. Among the files that theLinux kernel will try to execute is /sbin/init. If Linux cannot findone of these processes, it throws a kernel panic and halts.
The kernel gives the init process an ID of 1 or PID 1. All otheruserspace processes are forked from init, and therefore, PID 1 claimsancestral rights to all other userspace processes. PID 1 alsoautomatically will become the direct parent process of any userspace processthat is orphaned.
A Little Bit of HistoryNow that I have set the stage for the article and given you a very basicunderstanding of what init is and does, I'd like to digress intoa little bit of UNIX history.
There has been a lot of diversity in the initialization schemes forUNIX-like operating systems over time. Two of the most important initschemes that had a historical impact on how different Linux distributionsdo things are the rc scheme used in the 4.4 BSD and the SysV schemeused in SunOS and Solaris.
The 4.4 BSD init system is pretty simple and monolithic. When booting,the kernel runs /sbin/init, which would spawn a shell to run the /etc/rcscript. The /etc/rc script contained commands to check the integrity of harddrives and mount them, start other processes, and start the networkingsubsystem. This scheme was contained completely within a few scripts:namely /etc/rc, /etc/rc.local and /etc/netstart. This scheme also hadno specific shutdown procedure. Init would receive a SIGTERM signal andsend a SIGHUP and/or a SIGTERM to its children, and after all processesexited, it would drop to single-user mode and shut down.
Today, the systems that have inherited the rc initialization scheme areFree-BSD, Net-BSD and the Slackware Linux distribution. These modernsystems have improved quite a bit on the original 4.4 BSD scheme andare much more modular than the original.
Most other Linux distributions have, historically, been adepts of theSysV scheme, which originally was implemented in AT&T UNIX and derivativesystems like Solaris.
System V InitA Linux distribution implementing a SysV scheme can be in one of manydistinct states in which a predetermined number of processes may berunning. These states are called runlevels and to get to a certainrunlevel means that the system is in a certain operational stage.
The meaning for each runlevel may vary based on your distributionof Linux. For example, there are a few distributions (such as Ubuntu) thatuse runlevel 2 to mean multi-user graphical mode with networkingenabled. Others (like Fedora) use runlevel 5 to mean the same thing.
In a SysV Linux machine, the kernel runs /sbin/init as usual,which in turn will load parameters and execute directives definedin /etc/inittab. This file defines the default runlevel for the wholesystem, describes what happens when Ctrl-Alt-Del is pressed, loads keymapfiles, defines which terminals to spawn gettys for, spawns terminal loginprocesses, runs the /etc/init.d/rcS script, and it also influences the orderof execution of other runlevel scripts.
The /etc/init.d/rcS script will put the system in a single-user modein order to finish probing hardware, mount disks, set hostname, set upnetworking and so on. Take a look at /etc/rcS.d/ in a Debian 7 system forall the gory details. Next, /sbin/init will switch itself to the defaultrunlevel to start all the system services. The default runlevel valueis defined in the initdefault line of /etc/inittab.
This actually translates into a call to the /etc/init.d/rc script withthe parameter of 2 for the runlevel value. The rc script will thenexecute all of the K* (for Kill) and S* (for Start) scripts in the/etc/rc2.d/ directory. These are actually links to the real scripts in/etc/init.d/. The names of the links follow the formatS##
A system that uses the SysV scheme usually comes with the service programused to manage the services while the system is running. You can checkon the status of a service, or all services, and start or stop a service,respectively, using the service utility:
$ service
$ service status -all
# service
To manage the assignment of services to a particular runlevel, you canuse a tool called sysv-rc-conf, which manages the setup of all linksin the respective rc directories. You also can switch the runlevel ofthe system at any time when you use the commandtelinit as a privilegeduser. For example, telinit 6 will reboot a SysV system.
The SysV scheme still is in use today in Debian 7 (Wheezy)systems. However, the Debian developers will be changing the init systemin version 8 to systemd. I cover systemd in more detail below, but first,let's look at why we need a new init system.
The Problem with System V InitThe SysV scheme has been great, but it started to show its age aroundthe time when Linux on the desktop gained a little more momentum. When theSysV scheme originally was designed, computers where nothing like theyare today. SysV was not designed to handle certain things well:
USB devices.
External storage volumes.
Bluetooth devices.
The cloud.
The SysV scheme was designed for a world that was static and slow moving.This init scheme originally was responsible only for bringing the systeminto a normal running state after power on or gracefully shuttingdown services prior to shutdown. As a result, the design was strictlysynchronous, blocking future tasks until the current one had completed.
This left the system unable to handle various events that were notrelated to the startup or shutdown of the system. Things that we takefor granted today were really cumbersome to handle elegantly during theheyday of SysV init:
There was no real process supervision—for example, dæmons werenot automatically restarted when they crashed.
There was no real dependency checking. The order of script namingdetermined the order in which they were loaded.
The addition or removal of USB drives and other portable storage/networkdevices while the machine was running was cumbersome and oftentimesrequired a reboot.
There were no facilities to discover and scan for new storage deviceswithout locking the system, especially when a disk might not even power onuntil it was scanned.
There were no facilities to load firmware for a device, which may haveneeded to occur after it was detected but before it was usable.
Inevitably, around the 2005/2006 time frame, severalalternative efforts tried to fix all the issues with the SysVscheme. But the effort that looked most promising during that time wasthe Upstart init project sponsored by Canonical.
123next ›last »Enter to Win Archive DVD + Free Backup Solution
Download your free copy of the Storix Backup and Recovery Solution now and be automatically entered to win!
Goodbye, Pi. Hello, C.H.I.P.
1. It's completely open source. I don't just mean the software, either. The design and documentation are completely open source, so people can download the schematics and make their own version, adding improvements or tweaking the design.
2. The operating system is based on Debian, which means that it supports thousands of apps out of the box.
3. Its single core CPU runs at 1GHz, beating the Pi's 700MHz CPU.
4. It has double the RAM--512MB instead of 256MB.
5. It has 4GB of storage built in.
6. It has built-in Wi-Fi.
7. It has built-in Bluetooth.
8. It can connect to almost any screen. The base unit supports composite video output, and there are adapters for VGA and HDMI.
9. There is an optional case that adds a touchscreen and a keyboard. It's the size of the original Game Boy.
Of course, this isn't the first Raspberry Pi competitor to offer more features than the original, but there's one big difference. Whereas all of the others have been more expensive than the Pi, this one is cheaper. Much cheaper--the basic unit is only $9.
The project was launched on Kickstarter on May 7, 2015, with a modest$50,000 target, which it smashed within hours. As I write this, thetotal pledge is $1,329,290, and there are less than three weeks left to go.
As you read this, the figures are bound to have changed, so here's a link for you to check it out directly:https://www.kickstarter.com/projects/1598272670/chip-the-worlds-first-9-computer/video_share.
With a smaller profile than the Pi, a lower price tag, a more powerful processor and more memory, it could quickly replace Pi as the number-one choice for projects.
It's packed with pins and sockets to help build whatever your imagination cooks up. It has:
Parallel LCD output.Eight digital GPIOs.One PWM pin.SPI.TWI (I2C).UART.USB.MIPI-CSI.Touch panel input.Stereo audio out.Mono audio in.Composite video out.
They are continuing to tinker with the specifications leading up to the official release, so keep an eye on those.
The official public release is scheduled for next year, but crowdfunding backers will be able to land a "Kernel Hacker" package this September. This package is aimed at Linux developers who want to help to contribute to kernel modifications for the C.H.I.P. before its final release.
Once the crowdfunding project is completed, they will be releasing all the design docs to the community, so you can expect to see a number of similar devices popping up in the future!
May 2015 Issue of Linux Journal: Cool Projects
I love the Cool Projects issue. Don't get me wrong, most issues ofLinuxJournal are full of cool things to do, but this month, we do it justbecause of the cool factor. As you can imagine, no Cool Projects issue iscomplete without a Raspberry Pi article, and this one is particularlyawesome. But let me start off with a bit about our columns.
Reuven M. Lerner continues his series on Django, and this month, he covers migrations and updating databases. If you're a developer looking for aframework to start with, or if you're already using Django and want to learnmore, Reuven's series is a great way to begin. Dave Taylor follows Reuvenwith a new topic this month (you might remember Dave was working on aword search project in his last column). In this issue, he takes on the topic of how to make your shell scripts send text messages. It's agreat way to get instant notifications to users, which isn't usuallypossible from inside a script.
I describe a couple cool programs in this month's upfront section, starting with Budgie.If you like the simplicity of the Chrome desktop interface, but prefer afull-blown Linux system underneath, Budgie is perfect. I also talk aboutthe intricacies of the Linux permissions system and even a few Bitcoinclients. It's hard to beat the cool factor of Kyle Rankin's column thismonth, however, as he continues his series on Libreboot. People have beeninstalling open source on hard drives for years, but with Kyle'sassistance, you will learn to install the open-source BIOS replacement as well!
Be sure to check out Bharath Bhushan Lohray's article for an incredible home automationproject. Starting from scratch with a Raspberry Pi, some relays and somewiring, Bharath walks through the steps of using the GPIO pins to manage multiplesystems. Although it's certainly possible to buy one of the many embedded homeautomation kits available, starting from scratch allows for some seriouscustomization and infinite programability. If you've been struggling tochoose a brand of home automation systems to try, perhaps after readingthis article, thatquestion will become moot!
Rick Brown describes another awesome project, but this time it integrateswith existing systems. Specifically, he explains how he connected a Linuxsystem to a vehicle to get real-time operation data. Rick also shows howto design a display for the information, so that you're not grepping logfiles while driving!
In past issues, you have learned how to do basic encryption with Linux tools inorder to keep your sensitive data safe. This month, Adam Kosmin goes muchfurther and describes his complete system for keeping data secure. Usingfreely available tools and a handful of scripts and methods, he shows howto integrate secure encryption into your daily routine. If you want toencrypt your data, but find it complex and frustrating, be sure to readAdam's article.
The Cool Projects issue is a favorite of mine year after year. Not only isit a chance to start working on those ideas you've been putting off formonths, but it's also a great way to learn while playing. I learned moreabout how keyboards function while making my MAME cabinet than ever beforeor since. As a kid who took apart everything I got my hands on, the CoolProjects issue is an awesome way to learn how to put a few things backtogether! Whether you love projects or just want some tech tips,product announcements and programming lessons, this issue of LinuxJournal should provide lots of entertainment and education.
Available to Subscribers: May 1
Buy this issue nowSubscribe todayAlready a subscriber? Log in now to read this issue.Chrome-Colored Parakeets
I personally like Google's Chrome interface. It's simple, fast, elegantand did I mention fast? Unfortunately, I don't like how locked down theChrome OS is on a Chromebook, nor do I like its total dependence on Google. Ialso don't like the lack of ability to install Chrome easily on generichardware. Thankfully, Budgie is here to help.
If you like the simplicity and speed of the Chrome interface, butwant a full-blown system underneath that deceptively simple GUI, Iurge you to give Budgie a try. You either can download the Evolve-OS, or just install the PPA into a standard Ubuntusystem. I simply typed:sudo apt-add-repository ppa:evolve-os/ppasudo apt-get updatesudo apt-get install budgie-desktop
Then log out, and when logging in, choose the Budgie desktop insteadof Unity. You'll find a very Chrome-like interface but on top of afull-blown Linux system instead of Chrome! The preferences are fairlysimplistic, but the entire interface is designed to get out of the wayand let you work. Due to its blazing-fast speed and ease of use,the Budgie Desktop is this month's Editors' Choice. Give it a try today!