In a precedent Blog I talked about how to create an AWS linux instance. Some questions can be: How to create a new user and to connect with, how to transfert files from my workstation, how to connect to my oracle instance from my workstation and so on.
In this blog I am going to deal with some basic but useful administration tasks.
Changing my hostname
One thing we will probably do is to change the hostname. Indeed the linux is built with a generic hostname. Changing hostname include following tasks
Update /etc/hostname with the new hostname
[[email protected] etc]# vi hostname [[email protected] etc]# cat /etc/hostname primaserver.us-west-2.compute.internal [[email protected] etc]#
[[email protected] ORCL]# cat /etc/hosts 127.0.0.1 primaserver.us-west-2.compute.internal localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Update our /etc/sysconfig/network with the HOSTNAME value
[[email protected] sysconfig]# cat network NETWORKING=yes NOZEROCONF=yes HOSTNAME=primaserver.us-west-2.compute.internal [[email protected] sysconfig]#
To keep the change permanent we have to add in /etc/cloud/cloud.cfg file the line preserve_hostname: true
[[email protected] cloud]# grep preserve_hostname cloud.cfg preserve_hostname: true [[email protected] cloud]
The last step is to reboot the server
[[email protected] cloud]# reboot Using username "ec2-user". Authenticating with public key "imported-openssh-key" Last login: Mon Nov 14 03:20:13 2016 from 220.127.116.11.static.wline.lns.sme.cust.swisscom.ch [[email protected] ~]$ hostname primaserver.us-west-2.compute.internal
Creating a new user and connecting with
User creation is done by useradd as usual. But to be able to connect with this user we have to do some tasks. Suppose the new user is oracle.
With oracle we have to create a .ssh directory and adjust permissions on it
[[email protected] ~]# su - oracle [[email protected] ~]$ pwd /home/oracle [[email protected] ~]$ mkdir .ssh [[email protected] .ssh]$ chmod 700 .ssh
And then let’s create an authorized_keys file
[[email protected] ~]$ touch .ssh/authorized_keys [[email protected] ~]$ cd .ssh/ [[email protected] .ssh]$ vi authorized_keys [[email protected] .ssh]$ chmod 600 authorized_keys
The last step is to copy the content of our public key (we used for user ec2-user). Remember that we have created a key pair when we built our linux box (see corresponding blog ) into the authorized_keys under /home/oracle/.ssh/authorized_keys
cd /home/ec2-user/ cd .ssh/ cat authorized_keys >> /home/oracle/.ssh/authorized_keys
And now connection should be fine with my new user from my workstation using public DNS and putty.
Tranferring files from my workstation to the AWS instance
One need might be to transfer files from our local workstation to the our AWS instance. We can use WinSCP, we just have to use the key by importing our putty session (we already used to connect) into WinSCP and after we can connect. Launch WinSCP and use Tools option.
And then select the session we want to import and we should connect with WinSCP
Connecting to my oracle instance from my workstation
I have installed my oracle software and my database and listener are running. How to connect from my workstation? It is like we usually do. We just have to allow connection on the database port (here I am using the default 1521). Security Groups option is used for editing the inbound rules.
Using Add Rule, we can allow connection on port 1521. Of course we can filter the source for the access.