Ubuntu
Basic:
sudo apt update && sudo apt upgrade
apt-get -y install ifupdown vim* openssh-server network-manager
# apt-get -y install open-vm-tools
$ sudo hostnamectl set-hostname ns1
1
2
$ sudo nano /etc/hosts
123.234.12.32 ns1.dracula.host ns1
Turn the firewall on or off
To turn on the firewall, enter sudo ufw enable in a terminal.
To turn off the firewall, enter sudo ufw disable .
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 22
sudo ufw enable
sudo ufw disable
sudo ufw status
sudo ufw reload
Similarly, to close an opened port:
sudo ufw deny 22
To remove a rule, use delete followed by the rule:
sudo ufw --dry-run allow httpsudo ufw allow https sudo ufw allow HTTP
--------------------SSH------------------------
apt install openssh*sudo systemctl enable ssh sudo systemctl restart sshsudo systemctl restart sshd.service
systemctl status ssh sudo ufw allow ssh
To disable the SSH server on your Ubuntu system, simply stop the SSH service by running:
sudo systemctl disable --now ssh
Copy
Later, to re-enable it, type:
sudo systemctl enable --now ssh
---------ROOT passwd ------------------------
trusty@worldcm:~$ sudo -s
[sudo] password for trusty: # own password
root@worldcm:~#
trusty@worldcm:~$ sudo passwd root
[sudo] password for trusty: # own password
Enter new UNIX password: # set root password
Retype new UNIX password: # confirm
passwd: password updated successfully
trusty@worldcm:~$ su -
Password:# input root password
root@worldcm:~#
----------------------------------------
Allowing SSH root login on Ubuntu 20.04
Open the /etc/ssh/sshd_config file with administrative privileges and change the following line:
FROM:
#PermitRootLogin prohibit-password
TO:
PermitRootLogin yes
The quick way to do this job could be just to simply use the sed command as shown below:
$ sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Restart SSH service:
$ sudo systemctl restart ssh
By default the root’s password is not set on Ubuntu 20.04 and the error message Permission denied, please try again will appear when attempting to SSH login as a root user. From this reason we need to set root’s password. When prompted enter your current user password followed by new root password:
$ sudo passwd
[sudo] password for linuxconfig:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Given that your Ubuntu 20.04 system allows incoming traffic on port 22/ssh, you should now be ready to SSH login as root:
$ ssh root@ubuntu-server
root@ubuntu-server's password:
Welcome to Ubuntu Focal Fossa (GNU/Linux 5.3.0-23-generic x86_64)
Ubuntu 16.04
SSH Client : Ubuntu : Ubuntu
root@dlp:~# apt-get -y install openssh-server
root@dlp:~# vi /etc/ssh/sshd_config
# line 28: change to no
PermitRootLogin yes
root@dlp:~# systemctl restart ssh
-----------------------------------
26 # Authentication:
27 LoginGraceTime 120
28 #PermitRootLogin prohibit-password
29 PermitRootLogin yes
30 StrictModes yes
--------------------------
EXAMPLE # vi /etc/hosts
[2]
127.0.0.1 localhost 192.168.1.10 mail.worldcm.net mail 201.201.1.1 www.worldcm.net
Install SSH Client.
root@client:~# apt-get -y install openssh-client
[3]
Connect to the SSH server with a common user.
# ssh [username@hostname or IP address]
root@client:~# ssh ubuntu@dlp.srv.world
The authenticity of host 'dlp.srv.world (<no hostip for proxy command>)' can't be established.
ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:60:90:d8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'dlp.srv.world' (ECDSA) to the list of known hosts.
ubuntu@dlp.srv.world's password: # password of the user
ubuntu@dlp:~$ # just logined
[4]
It's possbile to execute commands on remote Host with adding commands to ssh command.
# for example, open /etc/passwd on remote host
ubuntu@client:~$ ssh ubuntu@dlp.srv.world "cat /etc/passwd"
ubuntu@dlp.srv.world's password:
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin ... ... ubuntu:x:1000:1000:ubuntu,,,:/home/ubuntu:/bin/bash sshd:x:108:65534::/var/run/sshd:/usr/sbin/nologin
on Ubuntu 16.04
sudo nano /etc/ssh/sshd_config
change
PermitRootLogin prohibit-password
to
PermitRootLogin yes
sudo service ssh restart
------enable ssh root access on Ubuntu 14.04------------
# vim /etc/ssh/sshd_config
PermitRootLogin without-password #[Just below it, add the following line:]
PermitRootLogin yes
#StrictModes yes #[you would have to comment below line ]
# service ssh restart
ssh stop/waiting
ssh start/running, process 6919
----------Update System---------------
root@worldcm:~# apt-get update
# update system
root@worldcm:~# apt-get -y upgrade
-------------------------------------------x-------------------------------------------------------
Network Settings
apt-get --reinstall install network-manager
# apt-get install ifupdown
# ifdown enp0s3; ifup enp0s3
apt-get install ifupdown
apt-get install ifupdown2
apt-get install netscript-2.4
# sudo ip addr add 10.102.66.200/24 dev enp2s0
# ip link set dev enp2s0 up
# ip link set dev enp2s0 down
# sudo ip route add default via 10.102.66.1
# ip route show
# ifconfig -a
# netplan generate
**** 2 network interfaces *******
LAN: enp0s3 WAN: enp0s8
# cd /etc/netplan
$ sudo nano /etc/netplan/50-cloud-init.yaml [ Ubuntu 18.04]
# vim /etc/netplan/01-netcfg.yaml
---------------------------------------------
### 1 LAN card
enp0s8:
dhcp4: no
dhcp6: no
addresses: [192.168.56.110/24, ]
gateway4: 192.168.56.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
#### 2 LAN Card
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
enp0s8:
dhcp4: no
dhcp6: no
addresses: [192.168.56.110/24, ]
gateway4: 192.168.56.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
-----------------------------------------------------
# netplan apply
Set Dynamic DHCP IP Address in Ubuntu
# vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp0s8:
dhcp4: yes
dhcp6: yes
Once done save and close the file and apply
$ sudo netplan apply
$ ifconfig -a
sudo ifconfig sudo ip addr show
ip addr show dev enp0s8
sudo netplan --debug apply
systemctl restart NetworkManager.service
service network-manager restart
# systemctl restart systemd-resolved
Make the configuration effective (no reboot needed):
# ifdown --force enp0s3 lo && ifup -a # systemctl unmask networking # systemctl enable networking # systemctl restart networking
##-----------------------------------------
root@dlp:~# vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
# comment out
#iface eth0 inet dhcp
# add these lines
iface eth0 inet static
address 10.0.0.30# IP address
network 10.0.0.0# network address
netmask 255.255.255.0# subnet mask
broadcast 10.0.0.255# broadcast address
gateway 10.0.0.1# default gateway
dns-nameservers 10.0.0.10# name server
root@dlp:~# ifdown eth0 && ifup eth0
[2]
Disable IPv6 if not needed.
root@dlp:~# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
root@dlp:~# sysctl -p
root@dlp:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:f9:15:ee inet addr:10.0.0.30 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:851 errors:0 dropped:0 overruns:0 frame:0 TX packets:753 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:79431 (79.4 KB) TX bytes:97008 (97.0 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1184 (1.1 KB) TX bytes:1184 (1.1 KB)
--