Hiển thị các bài đăng có nhãn Command. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Command. Hiển thị tất cả bài đăng

Thứ Sáu, 28 tháng 3, 2014

How to Repair, Restore, or Reinstall Grub 2 with a Ubuntu Live CD or USB

Grub 2 typically gets overridden when you install Windows or another Operating System. To make Ubuntu control the boot process, you need Reinstall (Repair/Restore) Grub using a Ubuntu Live CD.

Warning:

Using the sudo command, especially from a Live CD can do serious damage to your system. Read all instructions and confirm you understand before executing any commands. When pasting into the Terminal, useCtrl+Shift+V, NOT Ctrl+V.

Terminal Commands:

Mount the partition your Ubuntu Installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount /dev/sda5 /mnt.
sudo mount /dev/sdXY /mnt
Now bind the directories that grub needs access to to detect other operating systems, like so:

Now we jump into that using chroot.

Now install, check, and update grub.
This time you only need to add the drive letter (usually a) to replace X, for example: grub-install /dev/sdagrub-install –recheck /dev/sda.
grub-install /dev/sdXgrub-install --recheck /dev/sdX
Now grub is back, all that is left is to exit the chrooted system and unmount everything.

Shut down and turn your computer back on, and you will be met with the default Grub2 screen.
You may want to update grub or re-install burg however you like it.

Congratulations, you have just Repaired/Restored/Reinstalled Grub 2 with a Ubuntu Live CD!



Source: http://howtoubuntu.org/ 

Thứ Năm, 14 tháng 11, 2013

How To Add and Delete Users on Ubuntu 12.04 and CentOS 6

When you log into a new freshly spun up droplet, you are accessing it from the root user. Although this gives you the power to make any changes you need on the server, you are much better off creating another new user with root privileges on the virtual private server. Additionally, if other people will be accessing the virtual server, you will need to make new users for them as well. This tutorial will go over creating a new user, granting them root privileges, and deleting users.

When you perform any root tasks with the new user, you will need to use the phrase “sudo” before the command. This is a helpful command for 2 reasons: 1) it prevents the user making any system-destroying mistakes 2) it stores all the commands run with sudo to a file where can be reviewed later if needed. Keep in mind however, that this user is as powerful as the root user. If you only need a user for a limited number of tasks on the VPS, you do not need to give them root privileges. 

Setup


This tutorial requires access to the root user or a user with sudo privileges. 

You should have received your root password from the welcome email after you launched your droplet.

Users on Ubuntu 12.04


How to Add a User on Ubuntu 12.04


To add a new user in Ubuntu, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

As soon as you type this command, Ubuntu will automatically start the process:
  • Type in and confirm your password

  • Enter in the user’s information. This is not required, pressing enter will automatically fill in the field with the default information

  • Press Y (or enter) when Ubuntu asks you if the information is correct

Congratulations—you have just added a new user. You can log out of the root user by typingexit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
# User privilege specification
root    ALL=(ALL:ALL) ALL 
newuser ALL=(ALL:ALL) ALL

Press ‘cntrl x’ to exit the file and then ‘Y’ to save it.

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

Finish up by the deleting the user’s home directory:
 sudo rm -rf /home/newuser



Users on CentOS 6


How to Add a User on CentOS 6


To add a new user in CentOS, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

Follow up by providing the user with a new password, typing and confirming the new password when prompted:
sudo passwd newuser

Congratulations—you have just added a new user and their password. You can log out of the root user by typing exit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

You will find the section to make the user privilege modifications at the bottom of the file. Type “a” to start inserting text. Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
newuser ALL=(ALL)       ALL

Save and Exit the file by press “shift” ZZ. 

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

You can add the flag “-r” to the command if you would like to simultaneously remove the users’s home directory and files.
sudo userdel -r newuser

Next Steps


Once you have set up the users will you need, you can start building up your VPS. A good place to start is to install the LAMP stack (a collection of basic web server software) on your droplet, using the tutorials below. 

LAMP on Ubuntu 12.04 

LAMP on CentOS 6



By Etel Sverdlov

How to use FTP from the command line.

FTP (File Transfer Protocol) allows you to transfer files between your PC and other Internet systems (hosts). You can transfer files, work with local or remote directories, rename and display files, and execute system commands. Before you start, you must know how to log on to the remote system and have a userid and password on that system.

Note: Some systems allow anonymous ftp access. To use anonymous ftp, use anonymous as your userid andyour e-mail address as the logon password.


Logging Onto and Off of a Remote System

To begin using Microsoft's FTP client, Open a command prompt and switch to the destination directory (where you want the download file).
To start an FTP session, enter: ftp host_name
where hostname is the name or IP address of the remote system.
You will then be asked to enter your userid and password.
Once you have successfully logged onto a remote system, you will be able to use ftp commands to view a listing of files on the remote system and transfer files between the two systems.
Example: Download i386.exe (Windows NT 3.5 Resource Kit) from ftp://ftp.microsoft.com/bussys/winnt/winnt-public/reskit/nt35/i386 to C:\Temp\Download

  1. Open a command prompt. Enter CD C:\Temp\Download (assuming that directory exists).
    Enter: ftp ftp.microsoft.com

    You should now see a prompt similar to this:
    Connected to ftp.microsoft.com.
    220 Microsoft FTP Service
    User (ftp.microsoft.com:(none)):


  2. For the userid, Enter: anonymous

    You should see a prompt similar to this:
    331 Anonymous access allowed, send identity (e-mail name) as password.
    Password:


  3. Enter: userid@domain.com as the password at the "Password:" prompt.
    Note: Any e-mail address in a userid@domain.com format should work. You will not be able to see the password as you type it.


  4. To download i386.exe from the bussys/winnt/winnt-public/reskit/nt35/i386 directory, Enter: get bussys/winnt/winnt-public/reskit/nt35/i386/i386.exe
    Note: You could have also used ls to view the directory and file names, cd bussys/winnt/winnt-public/reskit/nt35/i386 to switch directories, and get i386.exe to download the file from within that directory.


  5. To end the FTP session, Enter: quit or bye.
Note: Once you have extracted the resource kit, you will have to expand individual files
example: expand choice.ex_ choice.exe


FTP Commands

For a list of FTP commands, at the "ftp>" prompt, Enter: help
When using ftp from the command prompt, the following list of supported commands will be displayed:
Note: Hover your mouse over a command to see what the output of "help *" is for that command.
!   
delete
literal
prompt
send
?   
debug
ls  
put 
status
append
dir
mdelete
pwd 
trace
ascii
disconnect
mdir
quit
type
bell
get 
mget
quote
user
binary
glob
mkdir
recv
verbose
bye 
hash
mls 
remotehelp
 
cd  
help
mput
rename
 
close
lcd 
open
rmdir
 
The question mark (?) command is equivalent to the help command. Typing help or ? followed by the name of a command will display a brief description of the command's purpose.
The exclamation point (!) can be used to shell to the system (command) prompt. Type Exit to return to the FTP session. You can also issue a subset of system commands to perform as you shell out, e.g., ! dir %windir% | more. When the commands in the shell have completed, you will be returned to the FTP session.
The pwd command will list the current directory on the remote machine. To change directories on the remote machine, use the cd command. To create a new directory on the remote machine, use the mkdir command followed by the name you would like to assign to the new directory. The lcd command can be used to change directories on the local (PC) machine.
To display a listing of files on the remote system, enter: ls or dir.
To download a file (copy a file from the remote system to your PC), you can use the command get or recvfollowed by the name of the file you would like to download. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is downloaded to your PC. To download multiple files, you can use the mget command followed by a descriptor for the files you would like to download (e.g.: *.f for all files ending in ".f" or *.* for all files). You will be prompted to indicate whether you would like to download each file in turn. To turn off this prompting, enter the prompt command prior to entering the mget command; you will receive the message "Interactive mode OFF" indicating that prompting has been deactivated.
By default, files are downloaded and uploaded in ASCII file transfer mode. To download or upload files using Binary format mode, enter the command Binary at the "ftp>" prompt prior to downloading or uploading the file(s). To return to ASCII file transfer mode, enter the ASCII command.
To upload a file (copy a file from your PC to the remote system), you can use the command put or send followed by the name of the file you would like to upload. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is uploaded to the remote system. The mput command can be used to upload multiple files.
You can use the close or disconnect command to drop the current ftp connection without exiting from the command enironment and then use the open command to connect to a new host.

Much of this article was taken from the dead link,http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html

To see the original article, go tohttp://web.archive.org/web/*/http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html



Source: http://www.tburke.net/info/misc/cmdline-ftp.htm

Ubuntu Linux: Compress files using tar Command

How do I compress and backup files using tar command to another directory on same computer or another Linux computer under Ubuntu Linux?

First, open up a terminal under Ubuntu Linux. Some directories such as /etc require root permissions to read and write for backup. So you may need to run tar command using sudo command. In this example backup, /etc and your /home/vivek to /backup directory, enter:
$ sudo mkdir /backup
$ sudo tar -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

Where,
  • z : Compress the backup file with 'gzip' to make it smaller.
  • c : Create a new backup archive called /backup/files.backup.Nov_6_2009.tar.gz.
  • v : Verbose mode, the tar command will display what it's doing to the screen.
  • p : Preserves the permissions of the files put in the archive for restoration later.
  • f /backup/files.backup.Nov_6_2009.tar.gz: Specifies where to store the backup, /backup/files.backup.Nov_6_2009.tar.gz is the filename used in this example.

How Do I Exclude Certain Files or Directories?

You can exclude all *.mp3 stored in /home/vivek/music directory with --exclude option:
$ sudo tar --exclude='/home/vivek/music/' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek
Another example (exclude ~/music/ and ~/Downloads/*.avi files):
$ sudo tar --exclude='/home/vivek/music/' --exclude='/home/vivek/Downloads/*.avi' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

How Do I See a List Of Files Stored In Tar Ball or an Archive?

Type the following command:
$ sudo tar -ztvf /backup/files.backup.Nov_6_2009.tar.gz
Where,
  • t: List the contents of an archive.

How Do I Restore Files?

You can use the command as follows to restore everything in / directory:
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /
OR
$ cd /
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz

Where,
  • -x: Extract the files.
  • -C / : Extract the files in / directory.
In this example, you are restoring to the /delta directory.
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /delta

How Do I Backup Files To a Remote Server Called backup.example.com?

Type the command as follows to backup /etc/ and /home/vivek directories to a remote system called backup.example.com:
$ sudo -s
# ssh user@backup.example.com "mkdir /backup"
# tar zcvpf - /etc/ /home/vivek | ssh user@backup.example.com "cat > /backup/files.backup.Nov_6_2009.tar.gz"

How Do I Restore Backup From a Remote System to Local Ubuntu Box?

Type the command
$ sudo -s
# cd /
# ssh user@backup.example.com "cat /backup/files.backup.Nov_6_2009.tar.gz" | tar zxpvf -
Source: http://www.cyberciti.biz/faq/ubuntu-howto-compress-files-using-tar/