I dont have a ginger ponytail, nor do I wear sandals, couple these two things together and you will understand why I find VI so confusing! Many times I’ve had to alter a config file on an appliance, or a Linux box, and sat frowning at VI wondering why I can’t change a one to a zero.
Note: Nano is easier, if possible try nano {filename} to save hassle. But on hardened appliances for example, it wont be there. 🙁
So, this article gives you enough information to open, edit, and save a file. If you want a massive tutorial on VI you are in the wrong place.
Solution
Not really part of VI but you need to know where the file is you want to edit, and the path to it;
[box]
For Example:
vi {filename}
vi {path}/{filename}
[/box]
You can ‘move around’ the file being edited with your arrow keys.
Deleting Text: Press the X key to delete the character that’s ‘under’ the cursor.
Selecting Text: Press (and hold) the V Key while using the arrow keys to select multiple text characters.
Note: From here you can CUT (press X), or COPY (press Y). To PASTE put the cursor where you want the text and press P.
Inserting Text: To actually type anything, you need to be in ‘insert‘ mode press I then type in your text.
Note: Some flavours of Linux give no indication you are in ‘insert‘ mode, (unlike the example below).
Saving and Exiting: you need to be in ‘command‘ mode to save and exit, to enter ‘command‘ mode press ESC. As above there may be no visual clue what mode you are in. To SAVE AND EXIT type :wq {Enter}. TO EXIT Type :q {Enter}. Basically q means quit and w means ‘write’ the changes.
Job done, now keep your Linux skills quiet or you may get your dinner money stolen, and not get a girlfriend.
Related Articles, References, Credits, or External Links
I’ve had windows for years; I knew the OS inside out. Recently, I switched to Mac. But I wondered how to edit the hosts file for my VPN connections and my servers. After some research, I found out how to do it and thought I will document it on PeteNetLive! 🙂
Solution
Open a terminal session and type in the following command;
[box]Sudo nano /etc/hosts[/box]
Note: I’m using nano for this but you can use vi to edit the document (sudo vi /etc/hosts).
You’ll be prompted to enter your password.
Then you will get this screen;
Type in an entry for example (Note: This is not my IP or my company’s IP!);
To Save, Press Control and O and Enter.
To Exit, press Control and X.
Related Articles, References, Credits, or External Links
When attempting to upload a file to your website, (in my case from within WordPress). You see this error.
Solution
If you are on ‘shared hosting‘ then you may not have access to your php.ini file, if that is the case you should add the following to your .htaccess file, (this will be a hidden file in the root folder of your website).
If , (like me), you have your own server, then you will need to edit the php.ini file directly, but where is it? Executing a ‘whereis php.ini‘ command in my case showed me a few copies in various locations, but which one was live?
I’m assuming your website is installed in /var/www/html, so change the commands if yours is in a different location. I’m going to create a .php file in the root of my website, then browse to this file, it will show me all my .php settings, and tell me where the live copy of php.ini is located.
I use nano, if you don’t have it installed, enter the hell that is the ‘vi editor’ and use that instead 🙂
[box]
nano /var/www/html/info.php
[/box]
Then paste in the following text;
[box]
<?php phpinfo(); ?>
[/box]
Then browse to the info.php file on your website with a web browser, i.e. http://www.your-website.com/info.php. You should see something like this.
You can see that the ‘Loaded Configuration File’ is in /etc/php.ini
WARNING: Now it’s a little bit of a security hole having this sat there, so let’s delete this file on the server with the following command;
[box]
rm /var/www/html/info.php
THEN Enter 'y' to confirm.
[/box]
How To Edit The php.ini File
Execute the following command;
[box]
nano /etc/php.ini
[/box]
Locate Upload_max_filesize and change its setting accordingly, by default it’s only 2MB.
Also change your post size setting, as the default is only 8MB.
Save and exit the file, then restart Apache.
[box]
/sbin/service httpd restart
[/box]
Try to upload your file again.
Related Articles, References, Credits, or External Links
I did a VMware VI3 to vSphere (4.1 U1) upgrade today. While bringing all the guest machines across, suddenly I could no longer browse the datastore, I only had one more guest to “Add to the inventory”, and all the mission critical machines were already migrated. I tried rebooting the virtual center, I tried restarting the ESXi host machines, still it sat saying “Searching Datastore……”.
Solution
1. I found the solution by accident. I was adding virtual machines to the new VSphere inventory, so I went in search of a method of doing it from the console, I was just about to:
Command to add a VMware guest to the inventory
[box]vmware-cmd -s register {full path to virtual machine}MACHINE_NAME.vmx[/box]
But, while looking in the folder with the guest files, I saw thousands of log files, I guess the VI client is struggling to parse them all, and display them. A quick internet search and I found out I can safely delete the log files.
2. Log into the ESX/ESXi servers console, for ESXi servers (version 4.0 and below) see here, for newer versions you can simply enable SSH access from Troubleshooting Mode Options > Enable Remote Tech support (SSH).
3. Log on as root and issue the following command to find the symlink path to your shared storage:
[box]ls -l /vmfs/volumes/[/box]
4. Now you know your symlink, you can change to the folder that contains the affected guest OS.
[box]cd /vmfs/volumes/{your symlink}/{your vm folder}[/box]
5. To get rid of all the log files, simply issue the following command.
[box]rm -f vmware-*.log[/box]
6. Now retry and you should see the folder contents when you “Browse Datastore”.
Related Articles, References, Credits, or External Links
I’ve seen this happen a few times now, while looking at your Virtual infrastructure, one or more client machines is greyed out and shown as (Orphaned).
Solution
If you have many guests VM’s on one host with this problem, you can cure this by removing the parent host and re-adding it to the cluster, then right clicking it and select “Reconfigure for HA“.
Or you can do the following, on a machine by machine basis.
1. Right click the affected VM and select “Remove from Inventory” (nothing gets deleted don’t worry.)
2. Select one of your ESX hosts > Configuration > storage > Right click the storage that holds the virtual machine we are dealing with and select “Browse Datastore” > Locate the machines .vmx file > Right click > Add to inventory > Follow the instructions.
Related Articles, References, Credits, or External Links
I needed to back up a Cisco firewall, and perform an upgrade remotely, despite my best efforts to use the ASDM and update via http, I had to go ‘old school’ and bring up a TFTP server on one of my CentOS Linux servers.
Solution
1. Log onto the server and install the xinetd TFTP Server. Execute the following command and follow the on-screen prompts.
[box]Using username “root”.
Last login: Thu Aug 7 17:58:10 2014 from midd-8.cable.virginm.net
[root@Web-Test ~]# yum install tftp tftp-server xinetd[/box]
2. Now you need to edit the config file, here I’m using nano, but you could use vi as well.
# default: off
# description: The tftp server serves files using the trivial file transfer
# protocol. The tftp protocol is often used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = yes
per_source = 11
cps = 100 2
flags = IPv4
}
[/box]
4. Edit the file and save it, so it looks like this;
[box]
# default: off
# description: The tftp server serves files using the trivial file transfer
# protocol. The tftp protocol is often used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -c -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
Note: if you run SELinux you may also need to execute the following command, ‘setsebool -P tftp_anon_write 1‘.
WARNINIG: This enables anonymous access on the TFTP root folder, if your server is public facing and not firewalled, then I would suggest you do what I do, (stop and start the service manually, and only open the firewall for TFTP when you need to use it – see below).
6. If you use iptables as a firewall, you will need to open the TFTP port (UDP Port 69).
10. I could SSH into the server and change to the /var/lib/tftpboot directory and see the file. But I’ve got WinSCP installed so I can view the backup with that.
11. Let’s see if we can copy a file off the TFTP server back to the firewall.
[box]
Petes-ASA# copy tftp flash
Address or name of remote host []? 123.123.123.123