# Remote Copying Tools, Archiving Tools, Backup & User Management

These are the topics that are covered in today's session.

@[Pranav Jambare](@AutomateMaster)

### **Remote Copying Tools:**

### **1 . SCP :**

* SCP stands for **secure copy** command in Linux.
    
* It is used to copy the files between the servers **securely**.
    
* It allows the secure transfer of files between the ***local host*** and the ***remote host*** or between ***two remote hosts***.
    

```bash
#Syntax :
scp <filename> <remoteuser>@<remoteuserIP>:<destination>
```

```bash
#Example:
scp myLinuxFile root@192.168.100.7:/root
```

### **2 . RSYNC:**

* RSYNC stands for remote synchronisation command in Linux.
    
* It synchronizes files from a source to a destination.
    
* It is famous for its **delta-transfer algorithm**, which **reduces** the amount of data sent over the network by sending only the **differences** between the source files and the existing files in the destination.
    
* RSYNC finds files that need to be transferred using a **checksum** algorithm that looks for files that have changed in size or in the **last-modified** time.
    

```bash
#Syntax:
rsync -av <filename> <remoteuser>@<remoteuserIP>:<destination>
```

```bash
#Example:
rsync -av myLinuxFile root@192.168.100.7:/root
```

### **3 . SFTP:**

* SFTP stands for **Safe File Transfer Protocol**.
    
* It is a **secure variant** of **FTP**.
    
* It is a part of the **SSH** Protocol and is designed to **securely** transfer files between remote systems via a **network** connection.
    

```bash
#Syntax:
sftp <username>@<userIP>
```

```bash
#Example:
sftp linuxUser@192.168.100.7
```

---

### **Archiving Tools:**

* Archiving is the process of **combining multiple files** into a **single package** called an **archive**.
    
* This archive can then be easily backed up, or simply kept on your machine as a way to organize your file system.
    

### 1 . **gzip**

```bash
#Syntax : (Compress)
gzip <filename>

#Example : 
gzip myFile
```

```bash
#Syntax : (Decompress)
gunzip <filename>.gz

#Example : 
gunzip myFile.gz
```

### **2 . xz**

```bash
#Syntax: (Compress)
xz <filename>

#Example:
xz myFile
```

```bash
#Syntax: (Decompress)
unxz <filename>.xz

#Example:
unxz myFile.xz
```

### **3 . bzip2**

```bash
#Syntax: (Compress)
bzip2 <filename>

#Example:
bzip2 myFile
```

```bash
#Syntax: (Decompress)
bzip2 <filename>.bz2

#Example:
bzip2 myFile.bz2
```

---

### **Backup:**

![Regular files being added to an archive with tar and then compressed with gzip.](https://cdn.hashnode.com/res/hashnode/image/upload/v1689087829751/8c63f4dd-7f5c-42ba-b610-dff65e5b9127.webp align="center")

Fig. Regular files being added to an archive with tar and then compressed with gzip.

* The tar utility is also able to compress an archive via a compression tool.
    
* To create an archive file :
    

```bash
#Syntax:
tar -cvzf <destn.backup> <sourcefile>

#Example:
tar -cvzf myLinuxFile.backup file1 file2 file3
```

* To extract an archive file:
    

```bash
#Syntax:
tar -xvf <destn.backup>

#Example:
tar -xvf myLinuxFile.backup
```

---

### **User Management:**

* A user is an entity, that can **manipulate** files and **perform** several other operations.
    
* Each user is assigned an ID that is unique for each user in the operating system.
    
* The **ID 0** is assigned to the **root user** and the **IDs 1 to 999** are assigned to the system users, hence the ids for the local user begin from 1000 onwards. 
    

**1 . Adding the User :**

* The command "***useradd***" or "***adduser***" can be used to create a new user in Linux also, the sudo permissions are required to perform this command.
    
    ```bash
    #Creating a User:
    root@myLinux:~# useradd testuser
    #OR
    root@myLinux:~# adduser testuser
    ```
    

**2 . Verifying the User:**

```bash
root@myLinux:~# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
```

**3 . Deleting the User:**

```bash
root@myLinux:~# userdel testuser
```

**4 . Managing the password policy:**

**Fields of /etc/password file:**

```bash
#The sudo permissions are required to perform this command
root@myLinux:~# cat /etc/passwd|tail -1
testuser:x:1001:1001::/home/testuser:/bin/sh
```

Where,

> testuser --&gt; **Name of user**
> 
> x --&gt; **Encrpyted password**
> 
> 1001 --&gt; **User id**
> 
> 1001 --&gt; **Group id**
> 
> :: --&gt; **Nickname (Con-name)**
> 
> /home/testuser --&gt; ***Home directory of the user***
> 
> */bin/bash* *\--&gt;* ***Default shell of user***

---

**Setting the password :**

```bash
#The sudo permissions are required to perform this command
root@myLinux:~# passwd testuser
#Next...
New password: 123 
Retype new password: 123
passwd: password updated successfully
```

---

**Changing the password policy:**

```bash
root@myLinux:~# chage -M 2 -m 5000 -W 4 -I 12 -E 2024-12-2
```

Where,

> \-M --&gt; maxdays password change date
> 
> \-m --&gt; mindays password change date
> 
> \-W --&gt; warning
> 
> \-I --&gt; Inactivity
> 
> \-E --&gt; Account Expiry date

---

**5 . Change / Restrict the User:**

**Give "No Login" to the User:**

```bash
root@myLinux:~# usermod testuser -s /sbin/nologin

#Verifying...
root@myLinux:~# su - testuser
Cannot change directory to /home/testuser:   
No such file or directory
This account is currently not available.
```

**To revert the changes to get a login:**

```bash
root@myLinux:~# usermod testuser -s /bin/sh

#Verifying...
root@myLinux:~# su - testuser
Last Login : .....
$whoami
testuser
```

---

**6 . Lock and Unlock User:**

```bash
# To Lock the user:
root@myLinux:~# usermod -L testuser

# To Unlock the user:
root@myLinux:~# usermod -U testuser
```

---

**7 . Adding Group:**

```bash
#The sudo permissions are required to perform this command
root@myLinux:~# groupadd testgroup

#Verifying the group...
root@myLinux:~# cat /etc/group|tail -1   
testgroup:x:1002:
```

---

**8 . Adding a user to a group:**

```bash
root@myLinux:~# usermod -G testgroup testuser 

#Verifying...
root@myLinux:~# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(testgroup)
```

---

**9 . Deleting a group:**

```bash
root@myLinux:~# groupdel testgroup

#Verifying...
root@myLinux:~# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
```

---

**10 . Change the user-id of the user:**

```bash
root@myLinux:~# usermod -u 1005 testuser

#Verifying...
root@myLinux:~# id testuser
uid=1005(testuser) gid=1001(testuser) groups=1001(testuser)
```

---
